Searching the net for source code samples turned nothing (blame Live and Google). The best approach I got was from a CodeProject article but the proposed GDI method does not work on Windows Mobile because the CAPTUREBLT flag is not supported. This means that I needed another solution.
GAPI seemed to be a very good candidate. It has a very simple API and I had used it in the past, but it is now declared deprecated by Microsoft and I was prompted to use Direct Draw instead. Willing to learn a bit more about this technology, I decided to give it a go and spent a couple of hours reading through MSDN docs to figure out how this can be done. As it turned out, it's very simple.
To capture the device screen using Direct Draw you need to follow these simple steps (I will write an article on this illustrating a desktop tool to capture the device screen via RAPI):
- Initialize Direct Draw using the DirectDrawCreate function using NULL as the first parameter.
- Set the cooperative level to DDSCL_NORMAL. This is enough for accessing the primary surface in read-only mode.
- Create the primary surface using this code.
- Get the surface's HDC and use it to create a compatible DC.
- Create a compatible bitmap using the screen dimensions and select it to the compatible DC.
- Blit from the surface DC to the compatible DC using BitBlt.
- Done! The compatible bitmap now contains the device's screen capture.
I wrote this using a DIBSection in order to marshal it via a RAPI call and was able to deserialize it on the desktop and display the device screen capture. I'm planning to use this same marshalling technique to implement a remote file browser using the device's own system image list.
Stay tuned for the article!