Link to home
Start Free TrialLog in
Avatar of khaledo
khaledo

asked on

Wait for me to hide

I want to hide my application window then capture the screen. I tried the code below but the screen shot capture parts of my application window. How to make my application wait till its window is completely hidden?

 Here is the code that does not work:

IsHide = AfxGetMainWnd()->SetWindowPos(AfxGetMainWnd(),0,0,0,0,SWP_HIDEWINDOW);
      ASSERT(IsHide);
      AfxGetMainWnd()->UpdateWindow();   //Make sure it is hidden
       
            // Wait until everybody repaints themselves
        while (PeekMessage(&msg,NULL,0,0,PM_REMOVE) != 0)
          {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
          }
      }

      keybd_event(VK_SNAPSHOT,1,0,0); //full screen
.........

Thanks
ASKER CERTIFIED SOLUTION
Avatar of atari
atari

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of khaledo
khaledo

ASKER

Thanks.

It worked, even when I set the timer to zero (because I thought it will be just like Wait() function if timer is not zero). I still do not understand why it worked. If updating starts after the end of the member function then we could simply put the function ShowWindow(SW_HIDE) in a separate member function and call it before the screen capturing. But such solution did not work while yours worked fine. If you can explain more I will be gratefull but for now, you solved my problem and I will accept your answer.
I worked this problem out for several hours, tried everything like WaitForSingleObject() or SendMessage(WM_PAINT,0,0) for instantaneously redrawing the mainframe-window, but nothing seems to work. Somewhere I had read that the WM_TIMER-message doesn't block any other windows-message and if you read in help-file of VC++ you find 'The WM_TIMER message is a low-priority message.', what means that all higher priority messages like windows-redrawing and something else are first processed and the WM_TIMER is the last one that will be processed. Sorry, the statement, that refreshes begin after ending of member-function was my own mistake. I hope that you got a little more ideas about that !

Bye,
atari