user32: Fix MonitorFromRect to cope with the absence of the MONITOR_DEFAULTTONEAREST flag.

Previously, the code would return any monitor found, regardless of 
whether it intersected the given rect or was the nearest monitor. This 
is fixed by adding a new flag that causes monitor_enum to only find the 
nearest monitor if MONITOR_DEFAULTTONEAREST is specified.

Also add a trace for MonitorFromWindow, since it is called in many 
places within user32 and so can't be traced using a relay trace.
This commit is contained in:
Rob Shearman 2008-02-15 15:22:44 +00:00 committed by Alexandre Julliard
parent a82f4dd9b7
commit 386427e739
1 changed files with 10 additions and 2 deletions

View File

@ -344,6 +344,7 @@ struct monitor_enum_info
UINT max_area;
UINT min_distance;
HMONITOR primary;
HMONITOR nearest;
HMONITOR ret;
};
@ -376,7 +377,7 @@ static BOOL CALLBACK monitor_enum( HMONITOR monitor, HDC hdc, LPRECT rect, LPARA
if (distance < info->min_distance)
{
info->min_distance = distance;
info->ret = monitor;
info->nearest = monitor;
}
}
if (!info->primary)
@ -403,9 +404,14 @@ HMONITOR WINAPI MonitorFromRect( LPRECT rect, DWORD flags )
info.max_area = 0;
info.min_distance = ~0u;
info.primary = 0;
info.nearest = 0;
info.ret = 0;
if (!EnumDisplayMonitors( 0, NULL, monitor_enum, (LPARAM)&info )) return 0;
if (!info.ret && (flags & MONITOR_DEFAULTTOPRIMARY)) info.ret = info.primary;
if (!info.ret)
{
if (flags & MONITOR_DEFAULTTOPRIMARY) info.ret = info.primary;
else if (flags & MONITOR_DEFAULTTONEAREST) info.ret = info.nearest;
}
TRACE( "%s flags %x returning %p\n", wine_dbgstr_rect(rect), flags, info.ret );
return info.ret;
@ -430,6 +436,8 @@ HMONITOR WINAPI MonitorFromWindow(HWND hWnd, DWORD dwFlags)
RECT rect;
WINDOWPLACEMENT wp;
TRACE("(%p, 0x%08x)\n", hWnd, dwFlags);
if (IsIconic(hWnd) && GetWindowPlacement(hWnd, &wp))
return MonitorFromRect( &wp.rcNormalPosition, dwFlags );