Module: wine Branch: master Commit: 386427e73901f2d520c583ff9fae3ad2642c1a22 URL: http://source.winehq.org/git/wine.git/?a=commit;h=386427e73901f2d520c583ff9f...
Author: Rob Shearman rob@codeweavers.com Date: Fri Feb 15 15:22:44 2008 +0000
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.
---
dlls/user32/misc.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/dlls/user32/misc.c b/dlls/user32/misc.c index f8cb157..65176e3 100644 --- a/dlls/user32/misc.c +++ b/dlls/user32/misc.c @@ -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 );