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.
Printable View
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.
I have tried:
had no effect.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);
}
}
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.
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".
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.
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.
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.
Code:void CMainFrame::On0Restore()
{
// TODO: Add your command handler code here
ShowWindow(SW_RESTORE);
SetForegroundWindow();
}
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 ?
Another attempt:
still not working correctly.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);
}
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. :cry: