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

Thread: Activate MDI window

  1. #31
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    I uploaded new version of project, I clean up CSystemTray class from CE stuff, but only from CSystemTray::OnTrayNotification method. I added the case for WM_LBUTTONDOWN, where I put a TRACE macro.
    Attached Files Attached Files

  2. #32
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    I have tried:
    Code:
    void CMainFrame::On0Restore()
    {
    	// TODO: Add your command handler code here
    
    	ShowWindow(SW_RESTORE);
    //	BringWindowToTop();
    //	SetForegroundWindow();
    
    	DWORD lockTimeOut = 0;
    	HWND hCurrWnd = ::GetForegroundWindow();
    	DWORD dwThisTID = ::GetCurrentThreadId(),
    		dwCurrTID = ::GetWindowThreadProcessId(hCurrWnd, 0);
    	if (dwThisTID != dwCurrTID)
    	{
    		::SystemParametersInfo(SPI_GETFOREGROUNDLOCKTIMEOUT, 0, &lockTimeOut, 0);
    		::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, 0, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
    		::AllowSetForegroundWindow(ASFW_ANY);
    		::SetForegroundWindow(GetSafeHwnd());
    		::BringWindowToTop(GetSafeHwnd());
    	}
    	if (dwThisTID != dwCurrTID)
    	{
    		::SystemParametersInfo(SPI_SETFOREGROUNDLOCKTIMEOUT, 0, (PVOID)lockTimeOut, SPIF_SENDWININICHANGE | SPIF_UPDATEINIFILE);
    		::AttachThreadInput(dwThisTID, dwCurrTID, FALSE);
    	}
    }
    had no effect.

  3. #33
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,598

    Re: Activate MDI window

    Good grief dude. All you need to do is copy some code from one of the messages that does work into your left button code. I don't know how much simpler to make it. Of course it didn't work, there's no code hooked up to it. The OnRestore code was working.

  4. #34
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,358

    Re: Activate MDI window

    Once you get it working by following GCDEFs advice and copy the working code to where you need it, do yourself a favor and take your code to the next level.

    Do this by refactoring and remove all the duplicate code. In other words put one copy of the copied code into a method, and call that method on other places in the code. You end up with fewer lines of code and only need to debug one method.

    For those folks that like to have labels for things, this is called the DRY principle; meaning, "Don't Repeat Yourself".

  5. #35
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    I have made those CSystemTray changes only because GCDEF told me that. But I don't know what is the purpose of this change. Sorry. The reported issue is on activating CMainFrame (MDI) window. And this MDI window activation could be done from anywhere, not from CSystemTray::whatever-method only.

  6. #36
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by GCDEF View Post
    Good grief dude. All you need to do is copy some code from one of the messages that does work into your left button code. I don't know how much simpler to make it. Of course it didn't work, there's no code hooked up to it. The OnRestore code was working.
    Sorry, I saw your message just now. Can you explain what you said with: "The OnRestore code was working" ? I have tried again, but I saw no change (meant is not working correctly).
    Thank you.
    Last edited by mesajflaviu; August 10th, 2020 at 07:14 AM.

  7. #37
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,598

    Re: Activate MDI window

    Quote Originally Posted by mesajflaviu View Post
    Sorry, I saw your message just now. Can you explain what you said with: "The OnRestore code was working" ? I have tried again, but I saw no change (meant is not working correctly).
    Thank you.
    Did you write any code to go with your left button down message yet?

  8. #38
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    When I moved the click on balloon code to icon left click the MDI app activation has been made, indeed. But I need this behavior on balloon click, not on icon left click. So, I am thinking how to simulate icon left click when user made click on balloon. However, CMainFrame::On0Restore code is not ok. I guess that code should work as expected. And is not happen.

  9. #39
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,598

    Re: Activate MDI window

    Quote Originally Posted by mesajflaviu View Post
    When I moved the click on balloon code to icon left click the MDI app activation has been made, indeed. But I need this behavior on balloon click, not on icon left click. So, I am thinking how to simulate icon left click when user made click on balloon. However, CMainFrame::On0Restore code is not ok. I guess that code should work as expected. And is not happen.
    You've been saying consistently that you need the left button on the tray icon to work. The balloon code works for me. Why are you saying On0Restore is not ok?

  10. #40
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    I guess I found the miss understanding here: I need to be functional the left click on tray balloon, not left click on the icon.

    So, let say we have the same call to CMainFrame::On0Restore method on icon left click and on balloon left click, ok ?

    When I call CMainFrame::On0Restore from left click button, the MDI window activation is correct, because NNN app has the focus already.

    When I call CMainFrame::On0Restore from left click on balloon, the MDI window activation is NOT correct, because MDI is not gain the focus. Here is the issue.
    Last edited by mesajflaviu; August 10th, 2020 at 10:44 AM.

  11. #41
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,598

    Re: Activate MDI window

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

  12. #42
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    And did you tried that code by clicking on tray balloon ? And when you tried this code have you started the application not from Visual Studio debugger but from Windows Explorer ?

  13. #43
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Quote Originally Posted by GCDEF View Post
    Code:
    void CMainFrame::On0Restore()
    {
    	// TODO: Add your command handler code here
    
    	ShowWindow(SW_RESTORE);
    	SetForegroundWindow();
    }
    The code from above is not working if the app NNN is started from Windows Explorer and is activated through left click on balloon (not on icon left click)
    Last edited by mesajflaviu; August 11th, 2020 at 04:53 AM.

  14. #44
    Join Date
    Jan 2009
    Posts
    369

    Re: Activate MDI window

    Another attempt:
    Code:
    void CMainFrame::On0Restore()
    {
    	// TODO: Add your command handler code here
    
    	ShowWindow(SW_RESTORE);
    	DWORD dwThreadID = GetWindowThreadProcessId(m_hWnd, NULL);
    	AttachThreadInput(GetWindowThreadProcessId(GetForegroundWindow()->GetSafeHwnd(), NULL),
    		GetCurrentThreadId(), TRUE);
    	SetWindowPos(&CWnd::wndTopMost, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
    	SetWindowPos(&CWnd::wndNoTopMost, NULL, NULL, NULL, NULL, SWP_NOMOVE | SWP_NOSIZE);
    
    	SetForegroundWindow();
    	SetActiveWindow();
    	SetFocus();
    
    	AttachThreadInput(dwThreadID, GetCurrentThreadId(), FALSE);
    }
    still not working correctly.
    Last edited by mesajflaviu; August 16th, 2020 at 02:18 PM.

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

    Re: Activate MDI window

    I guess you should investigate the difference between starting the .exe from VS and from Explorer. And how is this problem related to the tray...
    Sorry, I have currently a lot of work, so cannot help you more.
    Victor Nijegorodov

Page 3 of 3 FirstFirst 123

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)