Here's what my reference material has to say. If you want to take a screenshot just do it before you show your window for the first time or call ShowWindow(hWnd, SW_HIDE);
Where hWnd is a handle to your program's window.
@ dead_cell: I've never heard of simulate_keypress, would it be defined as:?
VOID simulate_keypress(BYTE bVk, BYTE bScan, DWORD dwFlags, DWORD dwExtraInfo )
keybd_event(bVk, bScan, dwFlags, dwExtraInfo);
You can use a bitmap to capture an image, and you can store the captured image in memory, display it at a different location in your application's window, or display it in another window.
In some cases, you may want your application to capture images and store them only temporarily. For example, when you scale or "zoom" a picture created in a drawing application, the application must temporarily save the normal view of the image and display the zoomed view. Later, when the user selects the normal view, the application must replace the zoomed image with a copy of the normal view that it temporarily saved.
To store an image temporarily, your application must call CreateCompatibleDC to create a DC that is compatible with the current window DC. After you create a compatible DC, you create a bitmap with the appropriate dimensions by calling the CreateCompatibleBitmap function and then select it into this device context by calling the SelectObject function.
After the compatible device context is created and the appropriate bitmap has been selected into it, you can capture the image. The Win32 API provides the BitBlt function to capture images. This function performs a bit block transfer ¾ that is, it copies data from a source bitmap into a destination bitmap. Because it copies data from bitmaps, you'd expect that two arguments to this function would be bitmap handles; however, this is not the case. Instead, BitBlt receives handles that identify two device contexts and copies the bitmap data from a bitmap selected into the source DC into a bitmap selected into the target DC. In this case, the target DC is the compatible DC, so when BitBlt completes the transfer, the image has been stored in memory. To redisplay the image, call BitBlt a second time, specifying the compatible DC as the source DC and a window (or printer) DC as the target DC.
The following example code, from an application that captures an image of the entire desktop, creates a compatible device context and a bitmap with the appropriate dimensions, selects the bitmap into the compatible DC, and then copies the image using the BitBlt function.
* Create a normal DC and a memory DC for the entire screen. The
* normal DC provides a "snapshot" of the screen contents. The
* memory DC keeps a copy of this "snapshot" in the associated
hdcScreen = CreateDC("DISPLAY", NULL, NULL, NULL);
hdcCompatible = CreateCompatibleDC(hdcScreen);
/* Create a compatible bitmap for hdcScreen. */
hbmScreen = CreateCompatibleBitmap(hdcScreen,
if (hbmScreen == 0)
/* Select the bitmaps into the compatible DC. */
if (!SelectObject(hdcCompatible, hbmScreen))
errhandler("Compatible Bitmap Selection", hwnd);
/* Hide the application window. */
* Copy color data for the entire display into a
* bitmap that is selected into a compatible DC.
errhandler("Screen to Compat Blt Failed", hwnd);
/* Redraw the application window. */