keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KE开发者_StackOverflow社区YUP, 0);
HBITMAP h;
OpenClipboard(NULL);
h = (HBITMAP)GetClipboardData(CF_BITMAP);
CloseClipboard();
...
normally this works well. but if the foreground window changes and locks the clipboard then it can't open clipboard.
Is there any alternative way to capture the screen -that can work in background too-?
thanks,
A simple scheme to capture the screen of monitor 1, that served me well but doesn't cover all corner cases:
- Get the screen device context.
- Create a device context compatible with the screen device context.
- Create a device independent bitmap (needed to get at the pixel data) that is as large as the screen resolution.
- Select the device independent bitmap into the compatible device context.
- Bit blit the screen device context onto the compatible device context.
- Deselect the device independent bitmap.
- The image data is now in the device independent bitmap.
- Optionally write the image data to file.
Capturing an Image
Could this be what you are looking for? What the example does is basically take a printscreen.
精彩评论