dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: how to track minimize, maximize events

  1. #1
    Join Date
    Aug 2006
    Posts
    515

    how to track minimize, maximize events

    From an old post here
    Quote Originally Posted by VladimirF
    To track minimize / maximize events, you should handle WM_WINDOWPOSCHANGED message.
    I would not worry about covering / uncovering of your window. Why? What if it is only partially covered? What if the top window is transparent?
    I tried it but it didn't help.
    Code:
    void CMainFrame::OnWindowPosChanged(WINDOWPOS* lpwndpos)
    {
    	CFrameWnd::OnWindowPosChanged(lpwndpos);
    
    	// TODO: Add your message handler code here
    	if (lpwndpos->flags & SWP_SHOWWINDOW)
    		AfxMessageBox(_T("Show"));
    	else if (lpwndpos->flags & SWP_HIDEWINDOW)
    		AfxMessageBox(_T("Hide"));
    	
    }
    The control nevers come in this function, only at start time and exit time. I know one way is to check them in WM_SIZE but is that the only way? I just need to catch the events when window is maximized and restored.

  2. #2
    Join Date
    Aug 2006
    Posts
    515

    Re: how to track minimize, maximize events

    I am checking for the window state in OnSize() but the problem is that when I call ShowWindow() inside OnSize() it causes a flicker for a second when applicatoin starts. I want to remove that.

    What I am doing is if user minimize application, it should hide, when user maximized it from system tray it should show up again. What is the best place to do that so it does not cause flicker! Thanks.

  3. #3
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    Re: how to track minimize, maximize events

    Hello,

    Maximizing / minimizing window can be done only by using buttons on the toolbar or by toolbar menu. One can check for the corresponding messages for the window concerned and take appropriate actions.

    Whether window is being maximized / minimized can be known if we store the previous window state. If you modify the PreTranslateMessage function to some thing as shown below, you can trap the maximizing event in a simplified way.

    Code:
    BOOL CMainFrame::PreTranslateMessage(MSG* pMsg) 
    {
    	// TODO: Add your specialized code here and/or call the base class
    	static int State = 0;
    	BOOL Flag = CFrameWnd::PreTranslateMessage(pMsg);
    	if ((State == SW_SHOWMAXIMIZED) != IsZoomed())
    		// Window is getting zoomed
    		...
    		State = SW_SHOWMAXIMIZED;
    	return Flag;
    }
    Regards,
    Pravin.
    Let me know if I have helped by rating this post

    Recent FAQs

    Drag an image
    Area of a window exposed on desktop
    Display rotated bitmap

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)