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

Thread: OnShowWindow not being called

Hybrid View

  1. #1
    Join Date
    Oct 2006
    Posts
    110

    OnShowWindow not being called

    I have a timer that updates the UI so I only want it it to be running when the window is visible. I have set up my OnShowWindow function to set and kill the timer as appropriate. The strange thing is, OnShowWindow is only being called when I start and close the application; not when I minimize, maximise, cover or uncover the window.

    Any ideas why this could be?

    Code:
    afx_msg void CMainWin::OnShowWindow( BOOL bShow, UINT nStatus )
    {
    	if(bShow)//Window has been made visible
    	{
    		MessageBox("Show");		
    		int timerConf = SetTimer(IDT_TIMER_MAIN, 250, 0);
    		if(timerConf ==0)
    		{
    			MessageBox("Timer did not start");
    		}
    		
    	}
    	else
    	{
    		MessageBox("Hide");		
    		KillTimer(IDT_TIMER_MAIN);
    		
    	}
    }

  2. #2
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: OnShowWindow not being called

    Quote Originally Posted by thorn
    ...The strange thing is, OnShowWindow is only being called when I start and close the application; not when I minimize, maximise, cover or uncover the window.
    It will be called, I believe, if you call ShowWindow() again.
    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?
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  3. #3
    Join Date
    May 2004
    Location
    45,000FT Above Nevada
    Posts
    1,539

    Re: OnShowWindow not being called

    In addition to what VladimirF suggested you might want to look at WM_ACTIVATE.
    Jim
    ATP BE400 CE500 (C550B-SPW) CE560XL MU300 CFI CFII

    "The speed of non working code is irrelevant"... Of course that is just my opinion, I could be wrong.

    "Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination are omnipotent. The slogan 'press on' has solved and always will solve the problems of the human race."...Calvin Coolidge 30th President of the USA.

  4. #4
    Join Date
    Oct 2006
    Posts
    110

    Re: OnShowWindow not being called

    Quote Originally Posted by VladimirF
    It will be called, I believe, if you call ShowWindow() again.
    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?
    You may be right. But why is OnShowWindow not working as the documentation says it should? Would it behave differently because it's a CFrameWnd?
    Last edited by thorn; December 11th, 2006 at 09:20 PM.

  5. #5
    Join Date
    Jul 2005
    Posts
    767

    Re: OnShowWindow not being called

    Quote Originally Posted by thorn
    You may be right. But why is OnShowWindow not working as the documentation says it should? Would it behave differently because it's a CFrameWnd?
    Read this line from VladimirF again
    Quote Originally Posted by VladimirF
    It will be called, I believe, if you call ShowWindow() again.
    OnShowWindow is handler called when WM_SHOWWINDOW message is posted and WM_SHOWWINDOW message is posted when you call ShowWindow or when ShowWindow is called.
    One's mistake cannot be your excuse!

  6. #6
    Join Date
    Oct 2006
    Posts
    110

    Re: OnShowWindow not being called

    What you are saying is correct but you seem to be misunderstanding my point.

    From here:

    A window is hidden or shown when the ShowWindow member function is called, when an overlapped window is maximized or restored, or when an overlapped or pop-up window is closed (made iconic) or opened (displayed on the screen). When an overlapped window is closed, all pop-up windows associated with that window are hidden.
    Now; the OnShowWindow function is being called when the program starts and closes but it does not seem to be called when the app is minimized or maximised or if another app is minimized or maximised above it. Which should happen.

  7. #7
    Join Date
    Jul 2005
    Posts
    767

    Re: OnShowWindow not being called

    Probably you should also go ahead and read this,
    Quote Originally Posted by MSDN
    The WM_SHOWWINDOW message is not sent under the following circumstances:


    When a top-level, overlapped window is created with the WS_MAXIMIZE or WS_MINIMIZE style.
    When the SW_SHOWNORMAL flag is specified in the call to the ShowWindow function.
    One's mistake cannot be your excuse!

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)