I (as many others) have been frustrated with the lack of a print screen button on the Pocket PC. So when my colleagues trial version of a screen capture utility expired I decided to create one myself.
After Googling around I found clues but no complete solution so I thought a nice first step would be to write a CodeProject article.
Shards of the (compact)code is derived from the net, but it has been remade, repackaged and recoded and is not easily traced to any single web page. So no credits to others at this time...
Using the Code
The application sends up a messagebox and then waits for the hardware button to be pressed (on the picture above it's the key marked in green). Hardware-keys depend on the device, so you'll have to figure out which button it is on your device if you deploy it to a real Pocket PC.
When the user presses the right button, a bmp-file called capture.jpg is saved under the root, another messagebox is presented, and the application ends. Simple as that.
The application uses the hardware button component to listen to button clicks. The main capture happens here though:
public class Capturer
public static extern int BitBlt(IntPtr hdcDest, int nXDest, int nYDest,
int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, uint dwRop);
private static extern IntPtr GetDC(IntPtr hwnd);
const int SRCCOPY = 0x00CC0020;
public static void Snapshot(string fileName, Rectangle rectangle)
IntPtr deviceContext = GetDC(IntPtr.Zero);
using(Bitmap capture = new Bitmap(rectangle.Width, rectangle.Height))
using (Graphics deviceGraphics = Graphics.FromHdc(deviceContext))
using (Graphics captureGraphics = Graphics.FromImage(capture))
BitBlt(captureGraphics.GetHdc(), 0, 0,
rectangle.Width, rectangle.Height, deviceGraphics.GetHdc(),
rectangle.Left, rectangle.Top, SRCCOPY);
The code gets hold of the screen device context by using
GetDC with a zero pointer and then
bitblts into a bitmap which is saved at a hardcoded location (the root directory).
2008-06-12: First version released.