简体   繁体   中英

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

keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY, 0);
keybd_event(VK_SNAPSHOT, 0x45, KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP, 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM