Click here to Skip to main content
15,891,692 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello..

Am having a window handle(hwnd). I want to take Screenshot of this window, I have used PrintWindow for this like this:

C++
void Screenshot()
{
  CImage image;
  image.Create(imageWidth, imageHeight, 24);
  CImageDC imageDC(image);

  HWND hwnd = ::FindWindow(0,"MyWindow");

  PrintWindow(hwnd, imageDC, PW_CLIENTONLY);

  image.Save("H:\\Image.bmp",ImageFormatBMP);
}


With this code i get the specified window image in H:\\ drive. Now my question is : How do i take a screenshot of MyWindow with user specified area i.e., by specifying x-axis & y-axis. I mean, i don't want the entire image of MyWindow, I need only specified area of MyWindow i.e., Somewhere in the middle of MyWindow.
So How do i specify x & y coordinates to PrintWindow. Alternatively. i have tried with BitBlt & StretchBlt but they are relatively slower than PrintWindow.
Please someone can tell how to accomplish this.

Thank you all :)
Posted

1 solution

You would need to write your own code to handle the WM_PRINT message[^].
 
Share this answer
 
Comments
Guru_C++ 14-Feb-13 5:50am    
How to write that WM_PRININT messages. I dont have any idea about that..
Richard MacCutchan 14-Feb-13 6:01am    
You just need to take the parameters passed in with the message and draw the contents of your window using that device context. Follow the link above to the documentation.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900