78,11 → 78,122 |
} |
} |
|
typedef struct _tagMONITORINFO |
{ |
DWORD cbSize; |
RECT rcMonitor; |
RECT rcWork; |
DWORD dwFlags; |
} _MONITORINFO, *_LPMONITORINFO; |
|
typedef struct _HMONITOR__* _HMONITOR; |
|
typedef BOOL(__stdcall* f_GetMonitorInfoA)(_HMONITOR hMonitor, _LPMONITORINFO lpmi); |
BOOL _GetMonitorInfoA(_HMONITOR hMonitor, _LPMONITORINFO lpmi) { |
// Calling dynamically, because Windows 95 does not support GetMonitorInfoA |
HMODULE hLib; |
f_GetMonitorInfoA fGetMonitorInfoA; |
BOOL res; |
|
hLib = LoadLibraryA("USER32.DLL"); |
if (!hLib) return 0; |
fGetMonitorInfoA = (f_GetMonitorInfoA)(void*)GetProcAddress(hLib, "GetMonitorInfoA"); |
if (fGetMonitorInfoA != 0) { |
res = fGetMonitorInfoA(hMonitor, lpmi); |
FreeLibrary(hLib); |
return res; |
} |
else { |
return false; |
} |
} |
|
typedef _HMONITOR(__stdcall* f_MonitorFromRect)(LPCRECT lprc, DWORD dwFlags); |
_HMONITOR _MonitorFromRect(LPCRECT lprc, DWORD dwFlags) { |
// Calling dynamically, because Windows 95 does not support MonitorFromRect |
HMODULE hLib; |
f_MonitorFromRect fMonitorFromRect; |
_HMONITOR res; |
|
hLib = LoadLibraryA("USER32.DLL"); |
if (!hLib) return 0; |
fMonitorFromRect = (f_MonitorFromRect)(void*)GetProcAddress(hLib, "MonitorFromRect"); |
if (fMonitorFromRect != 0) { |
res = fMonitorFromRect(lprc, dwFlags); |
FreeLibrary(hLib); |
return res; |
} |
else { |
return NULL; |
} |
} |
|
#define _MONITOR_DEFAULTTONULL 0x00000000 |
#define _MONITOR_DEFAULTTOPRIMARY 0x00000001 |
#define _MONITOR_DEFAULTTONEAREST 0x00000002 |
|
void _doMonitorAdjustments(LPRECT rcPlugin) { |
RECT rcMonitor; |
_MONITORINFO monInfo; |
_HMONITOR hMonitor; |
int leftAdjust, topAdjust; |
|
hMonitor = _MonitorFromRect(rcPlugin, _MONITOR_DEFAULTTONEAREST); |
if (hMonitor == NULL) return; |
|
memset(&monInfo, 0, sizeof(monInfo)); |
monInfo.cbSize = sizeof(monInfo); |
if (!_GetMonitorInfoA(hMonitor, &monInfo)) return; |
rcMonitor = monInfo.rcMonitor; |
|
leftAdjust = 0; |
topAdjust = 0; |
if (rcPlugin->left < rcMonitor.left) { |
leftAdjust += (rcMonitor.left - rcPlugin->left); |
} |
if (rcPlugin->right > rcMonitor.right) { |
leftAdjust -= (rcPlugin->right - rcMonitor.right); |
} |
if (rcPlugin->top < rcMonitor.top) { |
topAdjust += (rcMonitor.top - rcPlugin->top); |
} |
if (rcPlugin->bottom > rcMonitor.bottom) { |
topAdjust -= (rcPlugin->bottom - rcMonitor.bottom); |
} |
|
rcPlugin->left += leftAdjust; |
rcPlugin->right += leftAdjust; |
rcPlugin->top += topAdjust; |
rcPlugin->bottom += topAdjust; |
} |
|
/* |
* Centers a window to the center of its parent form but avoids |
* being spread across two screens. |
*/ |
void centre_window(HWND hwnd){ |
RECT rs, rd; |
HWND hw = GetDesktopWindow(); |
if (GetWindowRect(hw, &rs) && GetWindowRect(hwnd, &rd)) |
MoveWindow(hwnd,(rs.right + rs.left + rd.left - rd.right) / 2, |
(rs.bottom + rs.top + rd.top - rd.bottom) / 3, |
rd.right - rd.left, rd.bottom - rd.top, TRUE); |
RECT rcParent, rcWindowOriginal, rcPlugin; |
HWND hParent; |
|
hParent = GetParent(hwnd); |
if (hParent == NULL) hParent = GetDesktopWindow(); |
|
if (!GetWindowRect(hParent, &rcParent)) return; |
if (!GetWindowRect(hwnd, &rcWindowOriginal)) return; |
|
rcPlugin.left = (rcParent.right + rcParent.left + rcWindowOriginal.left - rcWindowOriginal.right) / 2; |
rcPlugin.top = (rcParent.bottom + rcParent.top + rcWindowOriginal.top - rcWindowOriginal.bottom) / 3; |
rcPlugin.right = rcPlugin.left + rcWindowOriginal.right - rcWindowOriginal.left; |
rcPlugin.bottom = rcPlugin.top + rcWindowOriginal.bottom - rcWindowOriginal.top; |
|
// Avoid that the window is spread between two screens |
_doMonitorAdjustments(&rcPlugin); |
|
MoveWindow(hwnd, |
rcPlugin.left, |
rcPlugin.top, |
rcPlugin.right - rcPlugin.left, |
rcPlugin.bottom - rcPlugin.top, |
TRUE); |
} |
|