0

In certain cases our application UI thread has to do heavy processing which may take more than 5 seconds and if this happens then OS thinks that my app got hanged and hence creates a ghost window.

This ghost window is correctly created on top of my app when my app is in restored state however when my app is in maximized state, this ghost window always picks Point(0,0) as its top left corner hence it looks like app is jumping to top left on its own. Can we avoid this jumping?

I don't want to disable ghost window creation for my app. One workaround could be to PeekMessage (don't remove) after regular interval. However, if possible I would like ghost window to appear whenever OS wants but it should be exactly where my app was before going to unresponsive state.

Please note, we customize the max window size for our application by overriding WM_GETMINMAXINFO.

------------This is how we set custom window size--------------

void CHangTestDlg::OnGetMinMaxInfo(MINMAXINFO* lpMMI)
{   
    lpMMI->ptMaxSize.x = 1011;
    lpMMI->ptMaxSize.y = 727;

    CRect rectWorkArea;
    SystemParametersInfo(SPI_GETWORKAREA, 0, (PVOID)&rectWorkArea, 0 );
    int ileft = (rectWorkArea.Width() - 1011)/2;
    int itop = (rectWorkArea.Height() - 727)/2;
    lpMMI->ptMaxPosition = CPoint(ileft, itop);

    CDialog::OnGetMinMaxInfo(lpMMI);
}

Ram
  • 31
  • 3
  • 1
    It doesn't "think" that your app is hung, your app is actually hung. Instead of looking for a band-aid for the ghost window problem, solve the *real* problem instead. Perform long-running operations on a worker thread. The Q&D fix is [DisableProcessWindowGhosting](http://msdn.microsoft.com/en-us/library/ms648415%28v=VS.85%29.aspx). – Hans Passant Aug 12 '13 at 12:10
  • @Hans: I don't want to use DisableProcessWindowGhosting. And I have already begun moving heavier code to a thread but for safety I want to fix the ghost window issue as well. I must be doing something wrong because, per [MSDN](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644927%28v=vs.85%29.aspx)"If a top-level window stops responding to messages for more than several seconds, the system considers the window to be not responding. In this case, the system hides the window and replaces it with a **ghost window that has the same Z order, location, size, and visual attributes.**" – Ram Aug 13 '13 at 06:33

0 Answers0