Wednesday, December 13, 2006

Customizing Windows Media Player appierence with UI plug-in

I recently had a project that had to customize the WMP's GUI. Not only withing Settings area, but should be able to paint anywhere on the WMP. Still, the WMP should think that it's an UI plugin, and be able to load/unload it on users' prompt.


As WMP does not expose any functionality for repainting itself, I had to figure out some way on how to do this. I've managed to implement this with a hook procedure. It is a pretty raw method, I think, and you can run it some troubles with different versions of WMP, maybe you'll have to create version for your plugin for each version of WMP. The troubles may be causes because of different looks of different versions of WMP. (WMP 10 and WMP 11 for example). But this is a working solution, and I don't know of any other so here it goes.

When you're creating a UI plugin, WMP calls Create method of your plug-in. It looks something like this:

HRESULT CYourPlugin::Create(HWND hwndParent, HWND *phwndWindow);

So the first parameter you have a parent window for the plugin. Logically it would pretty obvious that the parent for the plug-in is a WMP window, itself. But that's not really like that. To get the player window you'll have to do something like this:

HWND thePlayerWnd = GetParent(GetParent(GetParent(GetParent(hwndParent))));


yeah, there are a lof of windows within the WMP. So once you have the player's window, you can set a hook to listen to the messages that it receives like this:

DWORD threadID = GetCurrentThreadId();

HHOOK hook SetWindowsHookEx(WH_CALLWNDPROCRET, (HOOKPROC) MyHookProc, AfxGetInstanceHandle(), threadID);

Then you just monitor the messages sent to hook procedure and handle them on your as you wish. (please note that in this case messages will be sent to you AFTER WMP had processed them. That's because of WH_CALLWNDPROCRET flag).

when your plugin is being unloaded don't forget to unhook:

UnhookWindowsHookEx(hook);



That's it.

more info on hooks can be found here:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/winui/windowsuserinterface/windowing/hooks.asp

more info on WMP UI plugins here:
http://msdn2.microsoft.com/en-us/library/aa393418.aspx

If anybody has any question/suggestions please fill free to post them here.