mirror of
https://github.com/opencv/opencv.git
synced 2025-07-25 22:57:53 +08:00
Changes window position only if BOTH top corners are outside ALL monitors.
This commit is contained in:
parent
8ffa29473f
commit
183081ccd3
@ -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);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user