Commit bd1fab78 authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Don't start menu tracking when the owner window is invalid.

parent 354a74e0
......@@ -1848,6 +1848,11 @@ static BOOL MENU_ShowPopup( HWND hwndOwner, HMENU hmenu, UINT id, UINT flags,
}
/* store the owner for DrawItem */
if (!IsWindow( hwndOwner ))
{
SetLastError( ERROR_INVALID_WINDOW_HANDLE );
return FALSE;
}
menu->hwndOwner = hwndOwner;
menu->nScrollPos = 0;
......
......@@ -2932,6 +2932,20 @@ static void test_menu_trackpopupmenu(void)
gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
gflag_entermenuloop ? "WM_INITMENULOOP ": "",
gflag_initmenu ? "WM_INITMENU": "");
/* invalid window */
SetLastError(0xdeadbeef);
gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
ret = MyTrackPopupMenu( Ex, hmenu, TPM_RETURNCMD, 100,100, 0, NULL);
gle = GetLastError();
ok( !ret, "TrackPopupMenu%s should have failed\n", Ex ? "Ex" : "");
ok( gle == ERROR_INVALID_WINDOW_HANDLE, "TrackPopupMenu%s error got %u\n", Ex ? "Ex" : "", gle );
ok( !(gflag_initmenupopup || gflag_entermenuloop || gflag_initmenu),
"got unexpected message(s)%s%s%s\n",
gflag_initmenupopup ? " WM_INITMENUPOPUP ": " ",
gflag_entermenuloop ? "WM_INITMENULOOP ": "",
gflag_initmenu ? "WM_INITMENU": "");
/* now a somewhat successful call */
SetLastError(0xdeadbeef);
gflag_initmenupopup = gflag_entermenuloop = gflag_initmenu = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment