I'm finally feeling as though I am getting very close to the first non-beta release of MceFM.
I decided to remove MceFM's Queue page (which was by all accounts rather ugly anyway) and just to use the standard Windows Media Center music related pages (Now Playing, and View Queue).
I needed to detect Media Center events in order to know when a song changes, etc.
The standard way to do this is using the Media State Aggregation Service (MSAS), and I got this working. However it is rather flaky, and in the end I threw away the MSAS code I'd written, and took a different approach. The code is here if anyone wants it.
I'm embedding an instance of the Windows Media Player (WMP) ActiveX Control in a hidden window attached to the MceFM background application. The WMP control runs in "remote" mode, so that it reflects what is happening with the WMP instance used by Media Center. Using this control I can detect when songs start playing.
Detecting Remote Control button pushes
I also went through a weird and wonderful journey with regards to allowing users mark songs as Loved or Banned in Last.fm. Since I no longer have my own Queue page, I somehow needed to let the user press unused keys on the remote control when the Media Center "Now Playing" page was displayed. Two things were needed -- how to detect when the key is pressed, and how to know when the Now Playing page is being displayed.
I initially decided to use the colored buttons that appear on my remote control (Red, Green, Yellow, Blue) which are used for teletext. These buttons can't be intercepted using the normal techniques (low level system hooks), but can be detected using RegisterRawInputDevices and looking for RAWINPUT Windows Messages. I got this working fine on my computer (RAWINPUT 91=Red, 92=Green, 93=Yellow, 94=Blue).
My idea was to let people press the Red button to Ban a song, and the Green button to Love a song. I got this all working great. Then I hit two issues.
The first issue is that the RegisterRawInputDevices mechanism didn't work at all for extenders.
The second issue is that only European Media Center remote controls appear to have the colored buttons. D'oh.
I had to throw the whole approach overboard and start again from scratch.
I ended up letting you press the Left or Right arrow buttons on the remote control, which can be detected using low level system hooks, and do work on Extenders. Whew.