user: Fixed MonitorFromWindow behavior for an invalid window handle.
This commit is contained in:
parent
a990951358
commit
75fb678070
|
@ -543,12 +543,7 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate,
|
|||
mon_info.cbSize = sizeof(mon_info);
|
||||
if (template.style & DS_CENTER)
|
||||
{
|
||||
if (!(monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(),
|
||||
MONITOR_DEFAULTTOPRIMARY )))
|
||||
{
|
||||
pos.x = pos.y = 0; /* default to primary monitor */
|
||||
monitor = MonitorFromPoint( pos, MONITOR_DEFAULTTOPRIMARY );
|
||||
}
|
||||
monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY );
|
||||
GetMonitorInfoW( monitor, &mon_info );
|
||||
pos.x = (mon_info.rcWork.left + mon_info.rcWork.right - size.cx) / 2;
|
||||
pos.y = (mon_info.rcWork.top + mon_info.rcWork.bottom - size.cy) / 2;
|
||||
|
|
|
@ -375,12 +375,7 @@ static HWND DIALOG_CreateIndirect16( HINSTANCE16 hInst, LPCVOID dlgTemplate,
|
|||
mon_info.cbSize = sizeof(mon_info);
|
||||
if (template.style & DS_CENTER)
|
||||
{
|
||||
if (!(monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(),
|
||||
MONITOR_DEFAULTTOPRIMARY )))
|
||||
{
|
||||
pos.x = pos.y = 0; /* default to primary monitor */
|
||||
monitor = MonitorFromPoint( pos, MONITOR_DEFAULTTOPRIMARY );
|
||||
}
|
||||
monitor = MonitorFromWindow( owner ? owner : GetActiveWindow(), MONITOR_DEFAULTTOPRIMARY );
|
||||
GetMonitorInfoW( monitor, &mon_info );
|
||||
pos.x = (mon_info.rcWork.left + mon_info.rcWork.right - size.cx) / 2;
|
||||
pos.y = (mon_info.rcWork.top + mon_info.rcWork.bottom - size.cy) / 2;
|
||||
|
|
|
@ -430,7 +430,12 @@ HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
|
|||
if (IsIconic(hWnd) && GetWindowPlacement(hWnd, &wp))
|
||||
return MonitorFromRect( &wp.rcNormalPosition, dwFlags );
|
||||
|
||||
GetWindowRect( hWnd, &rect );
|
||||
if (GetWindowRect( hWnd, &rect ))
|
||||
return MonitorFromRect( &rect, dwFlags );
|
||||
|
||||
if (!(dwFlags & (MONITOR_DEFAULTTOPRIMARY|MONITOR_DEFAULTTONEAREST))) return 0;
|
||||
/* retrieve the primary */
|
||||
SetRect( &rect, 0, 0, 1, 1 );
|
||||
return MonitorFromRect( &rect, dwFlags );
|
||||
}
|
||||
|
||||
|
|
|
@ -146,10 +146,28 @@ static void test_ChangeDisplaySettingsEx(void)
|
|||
ok(res == DISP_CHANGE_SUCCESSFUL, "Failed to reset default resolution: %d\n", res);
|
||||
}
|
||||
|
||||
static void test_monitors(void)
|
||||
{
|
||||
HMONITOR monitor, primary;
|
||||
POINT pt;
|
||||
|
||||
pt.x = pt.y = 0;
|
||||
primary = MonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
|
||||
ok( primary != 0, "couldn't get primary monitor\n" );
|
||||
|
||||
monitor = MonitorFromWindow( 0, MONITOR_DEFAULTTONULL );
|
||||
ok( !monitor, "got %p, should not get a monitor for an invalid window\n", monitor );
|
||||
monitor = MonitorFromWindow( 0, MONITOR_DEFAULTTOPRIMARY );
|
||||
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTOPRIMARY\n", monitor, primary );
|
||||
monitor = MonitorFromWindow( 0, MONITOR_DEFAULTTONEAREST );
|
||||
ok( monitor == primary, "got %p, should get primary %p for MONITOR_DEFAULTTONEAREST\n", monitor, primary );
|
||||
}
|
||||
|
||||
|
||||
START_TEST(monitor)
|
||||
{
|
||||
init_function_pointers();
|
||||
test_enumdisplaydevices();
|
||||
test_ChangeDisplaySettingsEx();
|
||||
test_monitors();
|
||||
}
|
||||
|
|
|
@ -706,20 +706,10 @@ static void WIN_FixCoordinates( CREATESTRUCTA *cs, INT *sw)
|
|||
HMONITOR monitor;
|
||||
MONITORINFO mon_info;
|
||||
STARTUPINFOW info;
|
||||
POINT pt;
|
||||
|
||||
if (!IS_DEFAULT(cs->x) && !IS_DEFAULT(cs->cx) && !IS_DEFAULT(cs->cy)) return;
|
||||
|
||||
if (!(monitor = MonitorFromWindow( cs->hwndParent, MONITOR_DEFAULTTOPRIMARY )))
|
||||
{
|
||||
pt.x = pt.y = 0; /* default to primary monitor */
|
||||
if (!IS_DEFAULT(cs->x))
|
||||
{
|
||||
pt.x = cs->x;
|
||||
pt.y = cs->y;
|
||||
}
|
||||
monitor = MonitorFromPoint( pt, MONITOR_DEFAULTTOPRIMARY );
|
||||
}
|
||||
monitor = MonitorFromWindow( cs->hwndParent, MONITOR_DEFAULTTOPRIMARY );
|
||||
mon_info.cbSize = sizeof(mon_info);
|
||||
GetMonitorInfoW( monitor, &mon_info );
|
||||
GetStartupInfoW( &info );
|
||||
|
|
Loading…
Reference in New Issue