-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmultipleDisplay.cpp
More file actions
98 lines (86 loc) · 3.1 KB
/
multipleDisplay.cpp
File metadata and controls
98 lines (86 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include <windows.h>
#include "multimon.h"
#define MONITOR_CENTER 0x0001 // center rect to monitor
#define MONITOR_CLIP 0x0000 // clip rect to monitor
#define MONITOR_WORKAREA 0x0002 // use monitor work area
#define MONITOR_AREA 0x0000 // use monitor entire area
//
// ClipOrCenterRectToMonitor
//
// The most common problem apps have when running on a
// multimonitor system is that they "clip" or "pin" windows
// based on the SM_CXSCREEN and SM_CYSCREEN system metrics.
// Because of app compatibility reasons these system metrics
// return the size of the primary monitor.
//
// This shows how you use the multi-monitor functions
// to do the same thing.
//
// Íàèáîëåå ðàñïðîñòðàíåííûå ïðîáëåìíûå ïðèëîæåíèÿ ïðè ðàáîòå íà
// ìóëüòèìîíèòîðíàÿ ñèñòåìà ñîñòîèò â òîì, ÷òî îíè «çàæèìàþò» èëè «çàêðåïëÿþò» îêíà
// íà îñíîâå ñèñòåìíûõ ïîêàçàòåëåé SM_CXSCREEN è SM_CYSCREEN.
// Èç-çà ñîâìåñòèìîñòè ïðèëîæåíèé ýòè ïîêàçàòåëè ñèñòåìû
// âåðíóòü ðàçìåð îñíîâíîãî ìîíèòîðà.
//
// Ýòî ïîêàçûâàåò, êàê âû èñïîëüçóåòå ôóíêöèè íåñêîëüêèõ ìîíèòîðîâ
// ñäåëàòü òî æå ñàìîå.
void ClipOrCenterRectToMonitor(LPRECT prc, UINT flags)
{
HMONITOR hMonitor;
MONITORINFO mi;
RECT rc;
int w = prc->right - prc->left;
int h = prc->bottom - prc->top;
//
// get the nearest monitor to the passed rect.
// ïîëó÷àåì áëèæàéøèé ìîíèòîð ê ïåðåäàííîìó ïðÿìîóãîëüíèêó.
//
hMonitor = MonitorFromRect(prc, MONITOR_DEFAULTTONEAREST);
POINT pt;
pt.x = prc->right;
pt.y = prc->bottom;
//
// ïîëó÷àåì áëèæàéøèé ìîíèòîð ê ïåðåäàííîé òî÷êå.
//
hMonitor = MonitorFromPoint(pt, MONITOR_DEFAULTTONEAREST);
//
// get the work area or entire monitor rect.
// ïîëó÷èòü ðàáî÷óþ îáëàñòü èëè âåñü ïðÿìîóãîëüíèê ìîíèòîðà.
//
mi.cbSize = sizeof(mi);
GetMonitorInfo(hMonitor, &mi);
if (flags & MONITOR_WORKAREA)
rc = mi.rcWork;
else
rc = mi.rcMonitor;
//
// center or clip the passed rect to the monitor rect
// öåíòðèðóåì èëè îáðåçàåì ïåðåäàííûé ïðÿìîóãîëüíèê íà ïðÿìîóãîëüíèê ìîíèòîðà
//
if (flags & MONITOR_CENTER)
{
prc->left = rc.left + (rc.right - rc.left - w) / 2;
prc->top = rc.top + (rc.bottom - rc.top - h) / 2;
prc->right = prc->left + w;
prc->bottom = prc->top + h;
}
else
{
prc->left = max(rc.left, min(rc.right - w, prc->left));
prc->top = max(rc.top, min(rc.bottom - h, prc->top));
prc->right = prc->left + w;
prc->bottom = prc->top + h;
}
}
void ClipOrCenterWindowToMonitor(HWND hwnd, UINT flags)
{
RECT rc;
rc.left = GetSystemMetrics(SM_XVIRTUALSCREEN);
rc.right = GetSystemMetrics(SM_CXVIRTUALSCREEN);
rc.top = GetSystemMetrics(SM_YVIRTUALSCREEN);
rc.bottom = GetSystemMetrics(SM_CYVIRTUALSCREEN);
// ìû õîòèì ïîçèöèþ â ïðàâîì âåðõíåì óãëó âèðòóàëüíîãî ýêðàíà
//GetWindowRect(hwnd, &rc);
ClipOrCenterRectToMonitor(&rc, flags);
SetWindowPos(hwnd, NULL, rc.left, rc.top, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}