mirror of
https://github.com/reactos/reactos.git
synced 2024-12-28 10:04:49 +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
1 changed files with 19 additions and 7 deletions
|
@ -355,14 +355,26 @@ ParseCmdAndExecute(LPWSTR lpCmdLine, BOOL bIsFirstLaunch, int nCmdShow)
|
|||
if ((!hMutex) || (GetLastError() == ERROR_ALREADY_EXISTS))
|
||||
{
|
||||
/* 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 */
|
||||
ShowWindow(hWindow, SW_SHOWNORMAL);
|
||||
SetForegroundWindow(hWindow);
|
||||
if (bAppwizMode)
|
||||
PostMessage(hWindow, WM_COMMAND, ID_ACTIVATE_APPWIZ, 0);
|
||||
return FALSE;
|
||||
if (hWindow)
|
||||
{
|
||||
/* Activate the window in the other instance */
|
||||
SwitchToThisWindow(hWindow, TRUE);
|
||||
if (bAppwizMode)
|
||||
PostMessage(hWindow, WM_COMMAND, ID_ACTIVATE_APPWIZ, 0);
|
||||
|
||||
if (hMutex)
|
||||
CloseHandle(hMutex);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
CMainWindow wnd(&db, bAppwizMode);
|
||||
|
|
Loading…
Reference in a new issue