Skip to content

Commit

Permalink
user32: Set WM_CONTEXTMENU's wparam to the child window's handle.
Browse files Browse the repository at this point in the history
DefWindowProc() does not propagate the wparam; it updates it instead.
Spotted by YAL.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52327
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
  • Loading branch information
hdmdavies authored and julliard committed Jan 7, 2022
1 parent 1f17015 commit 3af8415
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
2 changes: 1 addition & 1 deletion dlls/user32/defwnd.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa

case WM_CONTEXTMENU:
if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
SendMessageW( GetParent(hwnd), msg, wParam, lParam );
SendMessageW( GetParent(hwnd), msg, (WPARAM)hwnd, lParam );
else
{
LONG hitcode;
Expand Down
29 changes: 27 additions & 2 deletions dlls/user32/tests/msg.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ typedef struct
} MEASURE_ITEM_STRUCT;

static BOOL test_DestroyWindow_flag;
static BOOL test_context_menu;
static HWINEVENTHOOK hEvent_hook;
static HHOOK hKBD_hook;
static HHOOK hCBT_hook;
Expand Down Expand Up @@ -9984,7 +9985,7 @@ static LRESULT MsgCheckProc (BOOL unicode, HWND hwnd, UINT message,
return 0;
}

if (message == WM_CONTEXTMENU)
if (!test_context_menu && message == WM_CONTEXTMENU)
{
/* don't create context menu */
return 0;
Expand Down Expand Up @@ -16148,6 +16149,13 @@ static const struct message WmRestoreActiveMinimizedOverlappedSeq[] =
{ 0 }
};

static struct message WmContextMenuSeq[] = {
{ WM_CONTEXTMENU, sent|wparam, 0 }, /* wparams set in the code */
{ WM_CONTEXTMENU, sent|wparam|defwinproc, 0 },
{ WM_CONTEXTMENU, sent|wparam|defwinproc, 0 },
{ 0 }
};

struct rbuttonup_thread_data
{
HWND hwnd;
Expand All @@ -16169,7 +16177,7 @@ static DWORD CALLBACK post_rbuttonup_msg( void *arg )

static void test_defwinproc(void)
{
HWND hwnd;
HWND hwnd, child[3];
MSG msg;
BOOL gotwmquit = FALSE;
POINT pos;
Expand Down Expand Up @@ -16219,6 +16227,23 @@ static void test_defwinproc(void)
flush_events();
ok_sequence(WmRestoreActiveMinimizedOverlappedSeq, "DefWindowProcA(SC_RESTORE):active minimized overlapped", TRUE);

child[0] = CreateWindowExA(0, "TestWindowClass", "1st child",
WS_VISIBLE | WS_CHILD, 0,0,500,100, hwnd, 0, 0, NULL);
child[1] = CreateWindowExA(0, "TestWindowClass", "2nd child",
WS_VISIBLE | WS_CHILD, 0,0,500,100, child[0], 0, 0, NULL);
child[2] = CreateWindowExA(0, "TestWindowClass", "3rd child",
WS_VISIBLE | WS_CHILD, 0,0,500,100, child[1], 0, 0, NULL);
flush_events();
flush_sequence();
test_context_menu = TRUE;
DefWindowProcA(child[2], WM_CONTEXTMENU, 0xcafe, 0);
test_context_menu = FALSE;
WmContextMenuSeq[0].wParam = (WPARAM)child[2];
WmContextMenuSeq[1].wParam = (WPARAM)child[1];
WmContextMenuSeq[2].wParam = (WPARAM)child[0];
ok_sequence(WmContextMenuSeq, "DefWindowProcA(WM_CONTEXTMENU)", FALSE);
DestroyWindow(child[0]);

GetCursorPos(&pos);
GetWindowRect(hwnd, &rect);
x = (rect.left+rect.right) / 2;
Expand Down

0 comments on commit 3af8415

Please sign in to comment.