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

This commit is contained in:
Alexandre Julliard 2011-04-21 14:35:11 +02:00
parent 354a74e004
commit bd1fab7862
2 changed files with 19 additions and 0 deletions

View File

@ -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;

View File

@ -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;