?
Solved

Help screen capturing and drawing a bitmap

Posted on 2007-10-11
5
Medium Priority
?
281 Views
Last Modified: 2008-01-09
Hi,

I wish to take a screenshot of a particular screen window and save it to file from a program.

I have hooked into the program and when the particular screen i want the screen grab of loads ( i do this using the window title ) i grab the screen.

now, this is working and i'm using WM_WINDOWPOSCHANGING as the event to do the creation, however as it looks like the screen hasn't finished drawing when this message is sent i don't get a screen shot with all the components on it. i only get half of them.

Can anyone suggest a message or method for when or where i can grab the screen and it will have finished drawing??

many thanks,

Matt.
0
Comment
Question by:flynny
5 Comments
 
LVL 31

Expert Comment

by:Zoppo
ID: 20055582
Hi flynny,

maybe you should use WM_WINDOWPOSCHANGED instead of WM_WINDOWPOSCHANGING - WM_WINDOWPOSCHANGED should be sent after the window has been moved/sized.

Hope that helps,

ZOPPO
0
 
LVL 39

Expert Comment

by:itsmeandnobodyelse
ID: 20055725
Hi Matt,

The suggestion of Zoppo wouldn't work if there are more than one WM_WINDOWPOSCHANGING  (therefore WM_WINDOWPOSCHANGED as well). If you do some of the drawing yourself (?), you could call a PostMessage with a private message id (WM_USER + something) to the window yourself. PostMessage means that it was put at end of queue. Then when handling the private message it should grab all  (hopefully).

Regards, Alex
0
 
LVL 86

Expert Comment

by:jkr
ID: 20057377
Just an idea - everything should be drawn when you call 'WaitForInputIdle()' on the process whose window you want to capture and the call returns...
0
 

Author Comment

by:flynny
ID: 20063891
Hi Guys,

thanks for the replie. As Itsme says catching th WM_WINDOWPOSCHANGED doesn't work.

ok, itsme in order to use the WM_USER message, i tried PostMessage(hwnd, WM_USER+10, 0, 0);
where i process the WM_WINDOWPOSCHANGED message, this does call my method however it seems to only be drawing a small pane of the window for some reason. (even though i know the window i have sent is the correct window.

jkr, if i were to use the waitforidleinput(), would i again for example at the end of my WM_WINDOWPOSCHANGED process be calling a <processname>.WaitForIdleInput() and then calling my bitmap write? would this cause problems as i'm waiting for no iput when im actually processing a message there too? (also how do i get the process name from the hwnd will GetWindowThreadProcessId do th trick?)

many thanks guys.

Matt.
0
 
LVL 39

Accepted Solution

by:
itsmeandnobodyelse earned 2000 total points
ID: 20064337
>>>> however it seems to only be drawing a small pane of the window for some reason.
it maybe means that between the WM_WINDOWPOSCHANGED and handling of the WM_USER + 10 there were more PostMessage calls which were queued later. You can come out of that timing issues by invoking a timer, e. g. by calling SetTimer(123, 1000);   what invokes a timer with id 123 in about 1000 milliseconds (that should enough to let happen any drawing). You would handle the timer in OnTimer if using MFC

   void MyDialog::OnTimer(UINT id)
   {
          if (id == 123)
          {
                 // get screenshot
                 KillTimer(123);
           }
   }

or by passing a  callback function to SetTimer as 3rd argument. In the latter case your callback function was called after time had expired. Note, you need to kill timer after handled as it is a periodic timer.

Regards, Alex
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question