Solved

Wait for me to hide

Posted on 1998-07-19
3
213 Views
Last Modified: 2013-11-20
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
0
Comment
Question by:khaledo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
atari earned 100 total points
ID: 1319453
I had a similar problem, I wanted to save the content of a mdi-window as .bmp after showing a CFileDialog for selecting a filename for my .bmp-file. After selecting a filename and clicking on OK the CFileDialog-Box is still displayed on the screen, so I cannot grab the content of my window. I solved this a little bit complicated with two timers, because the WM_TIMER-message  doesn't block any other messages, so all other messages are still processed. The problem for not updating the window-content is, that only after the end of your member-function the updating of your windows start, so the VK_UPDATE-message is much to early and will together processed while updating your windows.

So I solved it a little bit complicated, but it does work:
Start your screen-snapshot by calling AfxGetMainWnd()->OnBeginSnapshot();

Here are the protected declared functions in CMainFrame (my name for AfxGetMainWnd() in the following):

void CMainFrame::OnBeginSnapshot()
{
  ShowWindow(SW_HIDE);
  SetTimer(1,100,NULL);
  snapshot=TRUE;  // declared as protected in MainFrame.h
  endsnapshot=FALSE; // similar
}

void CMainFrame::OnSnapshot()
{
  keybd_event(VK_SNAPSHOT,1,0,0); //full screen
  KillTimer(1);
  SetTimer(1,100,NULL);
  snapshot=FALSE;
  endsnapshot=TRUE;
}

void CMainFrame::OnEndSnapshot()
{
  ShowWindow(SW_SHOWMAXIMIZED);
  KillTimer(1);
  snapshot=endsnapshot=FALSE;
}

void CMainFrame::OnTimer(UINT nIDEvent)
{
  if (snapshot)
      OnSnapshot();
  else
    if (endsnapshot)
        OnEndSnapshot();

  CMDIFrameWnd::OnTimer(nIDEvent);
}

The OnTimer()-call you can create with classwizard clicking on WM_TIMER-function for CMainFrame.

Maybe you can change the timer duration to get your best solution.

I hope this helps,
bye,
atari
0
 

Author Comment

by:khaledo
ID: 1319454
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.
0
 
LVL 1

Expert Comment

by:atari
ID: 1319455
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
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 113
move a line in eclipse 3 111
ERP and the other system process verification 5 26
Authenticate using sesu from script 7 160
Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

751 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