mirror of
https://github.com/reactos/reactos.git
synced 2024-10-06 09:24:11 +00:00
[RAPPS] Improve existing window re-use (#5617)
- Fix small race between CreateMutex and CMainWindow creating the window, and another instance getting NULL from FindWindow. - If the existing window is minimized, it should be restored.
This commit is contained in:
parent
7e2cd98688
commit
3f6af8b848
|
@ -355,15 +355,27 @@ ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
|
||||||
if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
|
if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
|
||||||
{
|
{
|
||||||
/* If already started, find its window */
|
/* If already started, find its window */
|
||||||
HWND hWindow = FindWindowW(szWindowClass, NULL);
|
HWND hWindow;
|
||||||
|
for (int wait = 2500, inter = 250; wait > 0; wait -= inter)
|
||||||
|
{
|
||||||
|
if ((hWindow = FindWindowW(szWindowClass, NULL)) != NULL)
|
||||||
|
break;
|
||||||
|
Sleep(inter);
|
||||||
|
}
|
||||||
|
|
||||||
/* Activate window */
|
if (hWindow)
|
||||||
ShowWindow(hWindow, SW_SHOWNORMAL);
|
{
|
||||||
SetForegroundWindow(hWindow);
|
/* Activate the window in the other instance */
|
||||||
|
SwitchToThisWindow(hWindow, TRUE);
|
||||||
if (bAppwizMode)
|
if (bAppwizMode)
|
||||||
PostMessage(hWindow, WM_COMMAND, ID_ACTIVATE_APPWIZ, 0);
|
PostMessage(hWindow, WM_COMMAND, ID_ACTIVATE_APPWIZ, 0);
|
||||||
|
|
||||||
|
if (hMutex)
|
||||||
|
CloseHandle(hMutex);
|
||||||
|
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CMainWindow wnd(&db, bAppwizMode);
|
CMainWindow wnd(&db, bAppwizMode);
|
||||||
MainWindowLoop(&wnd, nCmdShow);
|
MainWindowLoop(&wnd, nCmdShow);
|
||||||
|
|
Loading…
Reference in a new issue