Click here to Skip to main content
11,581,982 members (78,154 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: MFC

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

void Screenshot()
  CImage image;
  image.Create(imageWidth, imageHeight, 24);
  CImageDC imageDC(image);
  HWND hwnd = ::FindWindow(0,"MyWindow");
  PrintWindow(hwnd, imageDC, PW_CLIENTONLY);

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 Smile | :)
Posted 13-Feb-13 22:22pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You would need to write your own code to handle the WM_PRINT message[^].
Guru_C++ at 14-Feb-13 5:50am
How to write that WM_PRININT messages. I dont have any idea about that..
Richard MacCutchan at 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)

  Print Answers RSS
0 OriginalGriff 345
1 Sergey Alexandrovich Kryukov 220
2 Andy Lanng 114
3 virusstorm 109
4 Kornfeld Eliyahu Peter 90
0 OriginalGriff 1,358
1 Sergey Alexandrovich Kryukov 970
2 Abhinav S 671
3 F-ES Sitecore 505
4 Suvendu Shekhar Giri 448

Advertise | Privacy | Mobile
Web03 | 2.8.150603.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100