CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 3 123 LastLast
Results 1 to 15 of 45

Thread: Activate MDI window

  1. #1
    Join Date
    Jan 2009
    Posts
    369

    Activate MDI window

    How can I activate a MDI window after this one has been hidden in systemtray ?

    I have tried:
    Code:
    ShowWindow(SW_RESTORE);
    SetForegroundWindow();
    is shown, but not activated. I have to click on this window in order to be activated...
    also, I have tried:
    Code:
    ShowWindow(SW_RESTORE);
    SetForegroundWindow();
    BringWindowToTop();
    SetFocus();
    ShowWindow(SW_SHOW);
    ActivateFrame(SW_SHOW);
    the same result ... How can I activate this MDI window after has been shown ?

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    Where do you call this code from?
    Victor Nijegorodov

  3. #3
    Arjay's Avatar
    Arjay is online now Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,356

    Re: Activate MDI window

    Along the lines of what Victor is asking... Are you calling this from the same process the mdi window is in or from a separate process?

  4. #4
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by VictorN View Post
    Where do you call this code from?
    I call these methods in the CMainFrame code:

    Code:
    void CMainFrame::On0Restore() 
    {
    	// TODO: Add your command handler code here
    
    	ShowWindow(SW_RESTORE);
    	SetForegroundWindow();
    //	::BringWindowToTop(GetSafeHwnd());
    //	::SetFocus(GetSafeHwnd());
    //	::SetForegroundWindow(GetSafeHwnd());
    //	::ShowWindow(GetSafeHwnd(), SW_SHOW);
    }

  5. #5
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by Arjay View Post
    Along the lines of what Victor is asking... Are you calling this from the same process the mdi window is in or from a separate process?
    I am call these methods from the same process, from the same thread.

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    Quote Originally Posted by mesajflaviu View Post
    I call these methods in the CMainFrame code:

    Code:
    void CMainFrame::On0Restore() 
    {
    	// TODO: Add your command handler code here
    
    	ShowWindow(SW_RESTORE);
    	SetForegroundWindow();
    //	::BringWindowToTop(GetSafeHwnd());
    //	::SetFocus(GetSafeHwnd());
    //	::SetForegroundWindow(GetSafeHwnd());
    //	::ShowWindow(GetSafeHwnd(), SW_SHOW);
    }
    Did you debug this code? Is this method called?
    Victor Nijegorodov

  7. #7
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Of course that I've debugged. The only way to get the real focus is to call MessageBox (or a modal dialog) after I bring the MDI window to foreground. But this is not what I want. I only need to get the main frame of my app to foreground and set up as focused, ready to get another user commands.

  8. #8
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    OK! What message do you handle calling this
    Code:
    void CMainFrame::On0Restore()
    Could you post a small project reproducing this behavior?
    Victor Nijegorodov

  9. #9
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by VictorN View Post
    OK! What message do you handle calling this
    Code:
    void CMainFrame::On0Restore()
    Could you post a small project reproducing this behavior?
    Is coming from a system tray icon right click menu item.

  10. #10
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    Quote Originally Posted by mesajflaviu View Post
    Is coming from a system tray icon right click menu item.
    Again:
    Quote Originally Posted by VictorN View Post
    Could you post a small project reproducing this behavior?
    Victor Nijegorodov

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    I ask you for a small test project just because I have no time to create my own one and then try to guess how to simulate your problem!
    Victor Nijegorodov

  12. #12
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by VictorN View Post
    I ask you for a small test project just because I have no time to create my own one and then try to guess how to simulate your problem!
    Ok, I'll try to create a small project for this. I don't know if I could built today. But I come back. Seem very strange this issue because the called methods seem reliable and clear.
    Last edited by mesajflaviu; August 4th, 2020 at 04:27 AM.

  13. #13
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by Arjay View Post
    Along the lines of what Victor is asking... Are you calling this from the same process the mdi window is in or from a separate process?
    In fact, the app has single instance pattern. So, the issue occur when app is already started, and when user try to start another instance and a system tray balloon is shown, and user click on this volume, and then is fired code from the first post. And didn't work ok, instead of MDI get focus, I saw the app flash the task bar icon few times. So, I have tried this code too:
    Code:
    	ShowWindow(SW_RESTORE);
    
    	HWND hForegdWnd = ::GetForegroundWindow();
    	DWORD dwCurID = ::GetCurrentThreadId();
    	DWORD dwForeID = ::GetWindowThreadProcessId(hForegdWnd, NULL);
    
    	::AttachThreadInput(dwCurID, dwForeID, TRUE);
    	::SetForegroundWindow(m_hWnd);
    	::SetFocus(m_hWnd);
    	::AttachThreadInput(dwCurID, dwForeID, FALSE);
    with the same result.

  14. #14
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    19,783

    Re: Activate MDI window

    still waiting for the test project.
    Victor Nijegorodov

  15. #15
    Arjay's Avatar
    Arjay is online now Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,356

    Re: Activate MDI window

    Quote Originally Posted by mesajflaviu View Post
    In fact, the app has single instance pattern. So, the issue occur when app is already started, and when user try to start another instance and a system tray balloon is shown, and user click on this volume, and then is fired code from the first post. And didn't work ok, instead of MDI get focus, I saw the app flash the task bar icon few times. So, I have tried this code too:
    Code:
    	ShowWindow(SW_RESTORE);
    
    	HWND hForegdWnd = ::GetForegroundWindow();
    	DWORD dwCurID = ::GetCurrentThreadId();
    	DWORD dwForeID = ::GetWindowThreadProcessId(hForegdWnd, NULL);
    
    	::AttachThreadInput(dwCurID, dwForeID, TRUE);
    	::SetForegroundWindow(m_hWnd);
    	::SetFocus(m_hWnd);
    	::AttachThreadInput(dwCurID, dwForeID, FALSE);
    with the same result.
    So what started out as a post wondering why focus can't be set on an MDI application has now turned into a single instance tray notify application?

    Clearly it's a bit more complex. That being the case, Victor's ask of a sample app that repros the behavior is probably your best chance of receiving help.

Page 1 of 3 123 LastLast

Tags for this Thread

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)