开发者

Alternative way to capture the screen? (c++, windows OS)

开发者 https://www.devze.com 2022-12-21 08:24 出处:网络
keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0); keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KE开发者_StackOverflow社区YUP, 0);
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:

  1. Get the screen device context.
  2. Create a device context compatible with the screen device context.
  3. Create a device independent bitmap (needed to get at the pixel data) that is as large as the screen resolution.
  4. Select the device independent bitmap into the compatible device context.
  5. Bit blit the screen device context onto the compatible device context.
  6. Deselect the device independent bitmap.
  7. The image data is now in the device independent bitmap.
  8. 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消