Takes a screenshot for a specific window (hwnd) using the PrintWindow API. This works absolutely fine; a screenshot of the entire window is required. My question is: My window height is 742 and width is 653. If I want to take a screenshot somewhere in the middle of the window (not from 0,0). As I would point the x and y axes in PrintWindow. My snipnet code is as follows:
void Screenshot() { CImage image; image.Create(imageWidth, imageHeight, 24); CImageDC imageDC(image); HWND hwnd = ::FindWindow(0,"EIML"); PrintWindow(hwnd, imageDC, PW_CLIENTONLY); image.Save("H:\\out.jpg",ImageFormatJPEG); }
I tried alternative methods like BitBlt and StretchBlt, where we can specify the x and y axes. But for my design efficiency, time is very important. When I tried with BitBlt and StretchBlt, the time efficiency is about 25 ms. But when I take a screenshot with PrintWindow, its time efficiency is 6 ~ 8 ms. Therefore, this would be very useful for my project.
But the PrintWindow API always captures a window image from (0,0). Can someone tell / suggest me how to take a screenshot at the specified location, say, at x = 20 and y = 30.
Thanks.
source share