-
July 31st, 2020, 12:11 PM
#1
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 ?
-
July 31st, 2020, 01:10 PM
#2
Re: Activate MDI window
Where do you call this code from?
Victor Nijegorodov
-
July 31st, 2020, 05:01 PM
#3
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?
-
August 3rd, 2020, 12:42 AM
#4
Re: Activate MDI window
 Originally Posted by VictorN
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);
}
-
August 3rd, 2020, 12:42 AM
#5
Re: Activate MDI window
 Originally Posted by Arjay
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.
-
August 3rd, 2020, 03:08 AM
#6
Re: Activate MDI window
 Originally Posted by mesajflaviu
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
-
August 3rd, 2020, 05:18 AM
#7
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.
-
August 3rd, 2020, 05:24 AM
#8
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
-
August 3rd, 2020, 08:30 AM
#9
Re: Activate MDI window
 Originally Posted by VictorN
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.
-
August 3rd, 2020, 08:41 AM
#10
Re: Activate MDI window
 Originally Posted by mesajflaviu
Is coming from a system tray icon right click menu item.
Again:
 Originally Posted by VictorN
Could you post a small project reproducing this behavior?
Victor Nijegorodov
-
August 3rd, 2020, 09:03 AM
#11
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
-
August 3rd, 2020, 09:47 AM
#12
Re: Activate MDI window
 Originally Posted by VictorN
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.
-
August 4th, 2020, 10:15 AM
#13
Re: Activate MDI window
 Originally Posted by Arjay
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.
-
August 4th, 2020, 10:44 AM
#14
Re: Activate MDI window
still waiting for the test project.
Victor Nijegorodov
-
August 4th, 2020, 01:44 PM
#15
Re: Activate MDI window
 Originally Posted by mesajflaviu
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.
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|