When right click my tray icon, show the menu, And there is a menu item "Restore window". When click this menu item, it should restore window. My code implement "Restore window" below:
void CWinSearchDlg::OnTrayRestoreWnd()
{
DestroyTray();
ShowWindow(SW_SHOW);
if (CWnd::GetActiveWindow() != this)
{
SetActiveWindow();
AfxMessageBox(_T("SetActiveWindow"));
}
else
{
AfxMessageBox(_T("no SetActiveWindow")); //it goes here
}
BOOL bRet = FALSE;
bRet = SetWindowPos(&wndTop, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE);
if (bRet)
AfxMessageBox(_T("SetWindowPos true"));//it goes here
else
AfxMessageBox(_T("SetWindowPos false"));
bRet = FALSE;
bRet = SetForegroundWindow();
if (bRet)
AfxMessageBox(\_T("true SetForegroundWindow"));//it goes here
else
AfxMessageBox(\_T("false SetForegroundWindow"));
bRet = FALSE;
bRet = ::BringWindowToTop(this->GetSafeHwnd());
if (bRet)
AfxMessageBox(\_T("BringWindowToTop true"));//it goes here
else
AfxMessageBox(\_T("BringWindowToTop false"));
}
I've tried the code in blue font, but when restore the window, It doesn't bring to the top. Please give me a sign!