[0.4.10][WIN32SS] Fix regression CORE-15165 LMarbles Installer

Fixes CORE-15165 "'LMarbles 1.0.6 installer' from rapps can not be restored after it has been minimized once"
for LMarbles-installer and many similar installers.

It regressed once by 0.4.10-dev-340-g 75b09f3f88

Many Thanks to the fixes author Katayama Hirofumi MZ.

I decided to port back together with its user32-apitest 'SwitchToThisWindow' and that ran with
37 tests executed (0 marked as todo, 0 failures), 0 skipped.
in the back-port.

The fix is a squashed port of the following master-commits:
0.4.11-dev-632-g e39863bdf6 (#999)
0.4.11-dev-628-g 41b5f29514 (#995)
0.4.11-dev-561-g 5467cc9493 (#989)
0.4.11-dev-560-g 1f3353ac3b (#988)
0.4.11-dev-559-g 4bd0166e63 (#987)
0.4.11-dev-508-g 4ccad609e0 (#976)

test was added to master by:
0.4.11-dev-631-g 665269be9c (#998)
0.4.11-dev-515-g 3e00e7fb22 (#980)

releases/0.4.10 was the only affected branch, so starting with today we have
no affected branch left.
This commit is contained in:
Joachim Henze 2021-01-03 18:19:18 +01:00
parent de68701d21
commit 0e1bca258d
7 changed files with 294 additions and 20 deletions

View file

@ -35,6 +35,7 @@ list(APPEND SOURCE
SetProp.c
SetScrollInfo.c
SetScrollRange.c
SwitchToThisWindow.c
SystemParametersInfo.c
TrackMouseEvent.c
WndProc.c

View file

@ -0,0 +1,252 @@
/*
* PROJECT: ReactOS api tests
* LICENSE: GPL - See COPYING in the top level directory
* PURPOSE: Test for SwitchToThisWindow
* PROGRAMMERS: Katayama Hirofumi MZ <katayama.hirofumi.mz@gmail.com>
*/
#include "precomp.h"
static const WCHAR s_szClassName[] = L"SwitchTest";
static BOOL s_bTracing = FALSE;
static INT s_nWM_SYSCOMMAND_SC_RESTORE = 0;
static INT s_nWM_SYSCOMMAND_NOT_SC_RESTORE = 0;
static INT s_nWM_NCACTIVATE = 0;
static INT s_nWM_WINDOWPOSCHANGING = 0;
static INT s_nWM_ACTIVATE = 0;
#define TIMER_INTERVAL 200
static const char *
DumpInSMEX(void)
{
static char s_buf[128];
DWORD dwRet = InSendMessageEx(NULL);
if (dwRet == ISMEX_NOSEND)
{
strcpy(s_buf, "ISMEX_NOSEND,");
return s_buf;
}
s_buf[0] = 0;
if (dwRet & ISMEX_CALLBACK)
strcat(s_buf, "ISMEX_CALLBACK,");
if (dwRet & ISMEX_NOTIFY)
strcat(s_buf, "ISMEX_NOTIFY,");
if (dwRet & ISMEX_REPLIED)
strcat(s_buf, "ISMEX_REPLIED,");
if (dwRet & ISMEX_SEND)
strcat(s_buf, "ISMEX_SEND,");
return s_buf;
}
static void
DoMessage(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
if (uMsg == WM_TIMER || !s_bTracing)
return;
trace("%s: uMsg:0x%04X, wParam:0x%08lX, lParam:0x%08lX, ISMEX_:%s\n",
(InSendMessage() ? "S" : "P"), uMsg, (LONG)wParam, (LONG)lParam,
DumpInSMEX());
if (uMsg == WM_SYSCOMMAND) // 0x0112
{
ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
"InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
if (wParam == SC_RESTORE)
++s_nWM_SYSCOMMAND_SC_RESTORE;
else
++s_nWM_SYSCOMMAND_NOT_SC_RESTORE;
}
if (uMsg == WM_NCACTIVATE) // 0x0086
{
ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
"InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
++s_nWM_NCACTIVATE;
}
if (uMsg == WM_WINDOWPOSCHANGING) // 0x0046
{
ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
"InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
++s_nWM_WINDOWPOSCHANGING;
}
if (uMsg == WM_ACTIVATE) // 0x0006
{
ok(InSendMessageEx(NULL) == ISMEX_NOSEND,
"InSendMessageEx(NULL) was 0x%08lX\n", InSendMessageEx(NULL));
++s_nWM_ACTIVATE;
}
}
// WM_TIMER
static void
OnTimer(HWND hwnd, UINT id)
{
KillTimer(hwnd, id);
switch (id)
{
//
// SwitchToThisWindow(TRUE)
//
case 0: // minimize
SetForegroundWindow(GetDesktopWindow());
SetActiveWindow(GetDesktopWindow());
ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
ok(GetActiveWindow() == NULL, "GetActiveWindow() != NULL\n");
ok(GetFocus() == NULL, "GetFocus() != NULL\n");
CloseWindow(hwnd); // minimize
break;
case 1: // start tracing
ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
ok(GetFocus() == NULL, "GetFocus() != NULL\n");
s_nWM_SYSCOMMAND_SC_RESTORE = 0;
s_nWM_SYSCOMMAND_NOT_SC_RESTORE = 0;
s_nWM_NCACTIVATE = 0;
s_nWM_WINDOWPOSCHANGING = 0;
s_nWM_ACTIVATE = 0;
s_bTracing = TRUE;
SwitchToThisWindow(hwnd, TRUE);
trace("SwitchToThisWindow(TRUE): tracing...\n");
break;
case 2: // tracing done
s_bTracing = FALSE;
trace("SwitchToThisWindow(TRUE): tracing done\n");
ok(GetForegroundWindow() == hwnd, "GetForegroundWindow() != hwnd\n");
ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
ok(GetFocus() == hwnd, "GetFocus() != hwnd\n");
ok(s_nWM_SYSCOMMAND_SC_RESTORE == 1, "WM_SYSCOMMAND SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_SC_RESTORE);
ok(!s_nWM_SYSCOMMAND_NOT_SC_RESTORE, "WM_SYSCOMMAND non-SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_NOT_SC_RESTORE);
ok(s_nWM_NCACTIVATE == 1, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
ok(s_nWM_WINDOWPOSCHANGING == 2, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
ok(s_nWM_ACTIVATE == 1, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
break;
//
// SwitchToThisWindow(FALSE)
//
case 3: // minimize
SetForegroundWindow(GetDesktopWindow());
SetActiveWindow(GetDesktopWindow());
ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
ok(GetActiveWindow() == NULL, "GetActiveWindow() != NULL\n");
ok(GetFocus() == NULL, "GetFocus() != NULL\n");
CloseWindow(hwnd); // minimize
break;
case 4: // start tracing
ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
ok(GetFocus() == NULL, "GetFocus() != NULL\n");
s_nWM_SYSCOMMAND_SC_RESTORE = 0;
s_nWM_SYSCOMMAND_NOT_SC_RESTORE = 0;
s_nWM_NCACTIVATE = 0;
s_nWM_WINDOWPOSCHANGING = 0;
s_nWM_ACTIVATE = 0;
s_bTracing = TRUE;
SwitchToThisWindow(hwnd, FALSE);
trace("SwitchToThisWindow(FALSE): tracing...\n");
break;
case 5: // tracing done
s_bTracing = FALSE;
trace("SwitchToThisWindow(FALSE): tracing done\n");
ok(GetForegroundWindow() == NULL, "GetForegroundWindow() != NULL\n");
ok(GetActiveWindow() == hwnd, "GetActiveWindow() != hwnd\n");
ok(GetFocus() == NULL, "GetFocus() != NULL\n");
ok(!s_nWM_SYSCOMMAND_SC_RESTORE, "WM_SYSCOMMAND SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_SC_RESTORE);
ok(!s_nWM_SYSCOMMAND_NOT_SC_RESTORE, "WM_SYSCOMMAND non-SC_RESTORE: %d\n", s_nWM_SYSCOMMAND_NOT_SC_RESTORE);
ok(!s_nWM_NCACTIVATE, "WM_NCACTIVATE: %d\n", s_nWM_NCACTIVATE);
ok(!s_nWM_WINDOWPOSCHANGING, "WM_WINDOWPOSCHANGING: %d\n", s_nWM_WINDOWPOSCHANGING);
ok(!s_nWM_ACTIVATE, "WM_ACTIVATE: %d\n", s_nWM_ACTIVATE);
break;
default: // finish
DestroyWindow(hwnd);
return;
}
SetTimer(hwnd, id + 1, TIMER_INTERVAL, NULL);
}
static LRESULT CALLBACK
WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
DoMessage(hwnd, uMsg, wParam, lParam);
switch (uMsg)
{
case WM_CREATE:
SetTimer(hwnd, 0, TIMER_INTERVAL, NULL);
break;
case WM_TIMER:
OnTimer(hwnd, (UINT)wParam);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, uMsg, wParam, lParam);
}
return 0;
}
START_TEST(SwitchToThisWindow)
{
WNDCLASSW wc;
HICON hIcon;
HCURSOR hCursor;
ATOM atom;
HWND hwnd;
MSG msg;
hIcon = LoadIcon(NULL, IDI_APPLICATION);
ok(hIcon != NULL, "hIcon was NULL\n");
hCursor = LoadCursor(NULL, IDC_ARROW);
ok(hCursor != NULL, "hCursor was NULL\n");
ZeroMemory(&wc, sizeof(wc));
wc.lpfnWndProc = WindowProc;
wc.hInstance = GetModuleHandleW(NULL);
wc.hIcon = hIcon;
wc.hCursor = hCursor;
wc.hbrBackground = (HBRUSH)(COLOR_3DFACE + 1);
wc.lpszClassName = s_szClassName;
atom = RegisterClassW(&wc);
ok(atom != 0, "RegisterClassW failed\n");
if (!atom)
{
skip("atom is zero\n");
DestroyIcon(hIcon);
DestroyCursor(hCursor);
return;
}
hwnd = CreateWindowW(s_szClassName, L"SwitchToThisWindow", WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT, CW_USEDEFAULT, 100, 100,
NULL, NULL, GetModuleHandleW(NULL), NULL);
ok(hwnd != NULL, "CreateWindowW failed\n");
trace("hwnd: %p\n", hwnd);
if (!hwnd)
{
skip("hwnd is NULL\n");
UnregisterClassW(s_szClassName, GetModuleHandleW(NULL));
DestroyIcon(hIcon);
DestroyCursor(hCursor);
return;
}
ShowWindow(hwnd, SW_SHOWNORMAL);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
UnregisterClassW(s_szClassName, GetModuleHandleW(NULL));
DestroyIcon(hIcon);
DestroyCursor(hCursor);
}

View file

@ -37,6 +37,7 @@ extern void func_SetParent(void);
extern void func_SetProp(void);
extern void func_SetScrollInfo(void);
extern void func_SetScrollRange(void);
extern void func_SwitchToThisWindow(void);
extern void func_SystemParametersInfo(void);
extern void func_TrackMouseEvent(void);
extern void func_WndProc(void);
@ -78,6 +79,7 @@ const struct test winetest_testlist[] =
{ "SetProp", func_SetProp },
{ "SetScrollInfo", func_SetScrollInfo },
{ "SetScrollRange", func_SetScrollRange },
{ "SwitchToThisWindow", func_SwitchToThisWindow },
{ "SystemParametersInfo", func_SystemParametersInfo },
{ "TrackMouseEvent", func_TrackMouseEvent },
{ "WndProc", func_WndProc },

View file

@ -3,7 +3,8 @@
* PROJECT: ReactOS kernel
* PURPOSE: NtUserCallXxx call stubs
* FILE: win32ss/user/ntuser/simplecall.c
* PROGRAMER: Ge van Geldorp (ge@gse.nl)
* PROGRAMERS: Ge van Geldorp (ge@gse.nl)
* Katayama Hirofumi MZ (katayama.hirofumi.mz@gmail.com)
*/
#include <win32k.h>
@ -505,9 +506,32 @@ NtUserCallTwoParam(
}
case TWOPARAM_ROUTINE_SWITCHTOTHISWINDOW:
STUB
{
HWND hwnd = (HWND)Param1;
BOOL fAltTab = (BOOL)Param2;
Ret = 0;
Window = UserGetWindowObject(hwnd);
if (!Window)
{
break;
}
if (fAltTab)
{
if (Window->style & WS_MINIMIZE)
{
UserPostMessage(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
}
/* bring window to top and activate */
co_WinPosSetWindowPos(Window, HWND_TOP, 0, 0, 0, 0,
SWP_NOSIZE | SWP_NOMOVE | SWP_NOSENDCHANGING |
SWP_NOOWNERZORDER | SWP_ASYNCWINDOWPOS);
}
else
{
UserSetActiveWindow(Window);
}
break;
}
case TWOPARAM_ROUTINE_SETCARETPOS:
Ret = (DWORD_PTR)co_IntSetCaretPos((int)Param1, (int)Param2);

View file

@ -125,7 +125,7 @@ void ResizeAndCenter(HWND hwnd, int width, int height)
void MakeWindowActive(HWND hwnd)
{
if (IsIconic(hwnd))
ShowWindowAsync(hwnd, SW_RESTORE);
PostMessageW(hwnd, WM_SYSCOMMAND, SC_RESTORE, 0);
BringWindowToTop(hwnd); // same as: SetWindowPos(hwnd,HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE); ?
SetForegroundWindow(hwnd);
@ -171,6 +171,9 @@ BOOL CALLBACK EnumerateCallback(HWND window, LPARAM lParam)
if (!IsWindowVisible(window))
return TRUE;
if (GetWindow(window, GW_OWNER) != NULL)
return TRUE;
GetClassNameW(window, windowText, _countof(windowText));
if ((wcscmp(L"Shell_TrayWnd", windowText)==0) ||
(wcscmp(L"Progman", windowText)==0) )

View file

@ -688,6 +688,11 @@ EXTINLINE BOOL NtUserxUpdateUiState(HWND hWnd, DWORD Param)
return (BOOL)NtUserCallTwoParam((DWORD_PTR)hWnd, (DWORD_PTR)Param, TWOPARAM_ROUTINE_ROS_UPDATEUISTATE);
}
EXTINLINE VOID NtUserxSwitchToThisWindow(HWND hWnd, BOOL fAltTab)
{
NtUserCallTwoParam((DWORD_PTR)hWnd, (DWORD_PTR)fAltTab, TWOPARAM_ROUTINE_SWITCHTOTHISWINDOW);
}
EXTINLINE BOOL NtUserxShowOwnedPopups(HWND hWnd, BOOL fShow)
{
return (BOOL)NtUserCallTwoParam((DWORD_PTR)hWnd, fShow, TWOPARAM_ROUTINE_SHOWOWNEDPOPUPS);

View file

@ -81,20 +81,7 @@ BringWindowToTop(HWND hWnd)
VOID WINAPI
SwitchToThisWindow(HWND hwnd, BOOL fAltTab)
{
HWND hwndFG;
if (fAltTab)
{
if (IsIconic(hwnd))
ShowWindowAsync(hwnd, SW_RESTORE);
SetForegroundWindow(hwnd);
}
else
{
hwndFG = GetForegroundWindow();
ShowWindow(hwnd, SW_RESTORE | SW_SHOWNA);
SetWindowPos(hwnd, hwndFG, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE);
SetWindowPos(hwndFG, hwnd, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
}
NtUserxSwitchToThisWindow(hwnd, fAltTab);
}
@ -127,9 +114,9 @@ ChildWindowFromPointEx(HWND hwndParent,
BOOL WINAPI
CloseWindow(HWND hWnd)
{
SendMessageA(hWnd, WM_SYSCOMMAND, SC_CLOSE, 0);
return HandleToUlong(hWnd);
/* NOTE: CloseWindow does minimizes, and doesn't close. */
SetActiveWindow(hWnd);
return ShowWindow(hWnd, SW_SHOWMINIMIZED);
}
FORCEINLINE