Today’s post is probably not news to anyone… But I am sitting at work, doing nothing – bored out of my mind… I (and everyone else in this company) is being retrenched, and today, I am between job interviews.
Again, the source, for this and a whole bunch of other stuff, is here: RomyView.zip
Actually I just added the code explained in this article in the last few minutes and am uploading it as I write this.
My media player isn’t intended to be “production” code, but I do use it as my preferred player, so I’d like it to be as “complete” as I can get it. I had never heard of these standard keys… I stumbled onto them in the comments to this blog post today by Raymond Chen.
According to the MSDN page on WM_APPCOMMAND, the relevant messages are defined in WinUser.h. I’m still on Windows 7, so I browsed to “C:\Program Files\Microsoft SDKs\Windows\v7.1A\Include”, which is where my Platform SDK installation is found, and copied the relevant definitions into my code, resulting in this: (I added to existing code, so the code below is just the relevant bits. In the enum defined below, I also left out all the commands I don’t use to keep this brief. The source for download includes all the other commands as well.)
Players don’t need to support all of the commands above – handling play and pause is probably good enough. I just handled the ones that correlate with my existing implementation. Then in my media player form’s WndProc method, I added handlers for the messages: (Again, I’ve just copied the relevant bits here – the actual code has other unrelated handlers.)
Actually I should probably not have copied all of the below here… obviously the methods I call from each handler are irrelevant anyway, and all the handlers look almost identical. Note though, the MSDN documentation indicates that if you handle the WM_APPCOMMAND message, you need to return TRUE. Thus, in the switch statement below, I used a default case to take care of that, and every handler calls goto default, to do so and return.
Testing that this all works correctly is simple. You just call SendMessage to send one of the commands to your player form. Here’s an example, as well as the definition for SendMessage, in case you don’t already have it: