Commit b00dff83 authored by Vadim Pisarevsky's avatar Vadim Pisarevsky

Merge pull request #9456 from adishavit:issue_8840/CorrectlyRestoreWindowPosOnMultipleMonitors

parents 4a81492b 183081cc
...@@ -324,15 +324,34 @@ icvLoadWindowPos( const char* name, CvRect& rect ) ...@@ -324,15 +324,34 @@ icvLoadWindowPos( const char* name, CvRect& rect )
RegQueryValueEx(hkey, "Width", NULL, &dwType, (BYTE*)&rect.width, &dwSize); RegQueryValueEx(hkey, "Width", NULL, &dwType, (BYTE*)&rect.width, &dwSize);
RegQueryValueEx(hkey, "Height", NULL, &dwType, (BYTE*)&rect.height, &dwSize); RegQueryValueEx(hkey, "Height", NULL, &dwType, (BYTE*)&rect.height, &dwSize);
if( rect.x != (int)CW_USEDEFAULT && (rect.x < -200 || rect.x > 3000) ) // Snap rect into closest monitor in case it falls outside it. // Adi Shavit
rect.x = 100; // set WIN32 RECT to be the loaded size
if( rect.y != (int)CW_USEDEFAULT && (rect.y < -200 || rect.y > 3000) ) POINT tl_w32 = { rect.x, rect.y };
rect.y = 100; POINT tr_w32 = { rect.x + rect.width, rect.y };
if( rect.width != (int)CW_USEDEFAULT && (rect.width < 0 || rect.width > 3000) ) // find monitor containing top-left and top-right corners, or NULL
rect.width = 100; HMONITOR hMonitor_l = MonitorFromPoint(tl_w32, MONITOR_DEFAULTTONULL);
if( rect.height != (int)CW_USEDEFAULT && (rect.height < 0 || rect.height > 3000) ) HMONITOR hMonitor_r = MonitorFromPoint(tr_w32, MONITOR_DEFAULTTONULL);
rect.height = 100;
// if neither are contained - the move window to origin of closest.
if (NULL == hMonitor_l && NULL == hMonitor_r)
{
// find monitor nearest to top-left corner
HMONITOR hMonitor_closest = MonitorFromPoint(tl_w32, MONITOR_DEFAULTTONEAREST);
// get coordinates of nearest monitor
MONITORINFO mi;
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor_closest, &mi);
rect.x = mi.rcWork.left;
rect.y = mi.rcWork.top;
}
if (rect.width != (int)CW_USEDEFAULT && (rect.width < 0 || rect.width > 3000))
rect.width = 100;
if (rect.height != (int)CW_USEDEFAULT && (rect.height < 0 || rect.height > 3000))
rect.height = 100;
RegCloseKey(hkey); RegCloseKey(hkey);
} }
......
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