Store and load the dialog positions depending on monitor setup
[TortoiseGit.git] / src / Utils / Monitor.cpp
blob5a48fcd361d7d78be84ceb302bad50caa5e35877
1 // TortoiseGit - a Windows shell extension for easy version control
3 // Copyright (C) 2020 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "stdafx.h"
21 #include "Monitor.h"
22 #include <vector>
23 #include <algorithm>
25 static BOOL CALLBACK MonitorEnum(HMONITOR hMon, HDC /*hdc*/, LPRECT lprcMonitor, LPARAM pData)
27 MONITORINFOEX miex = { 0 };
28 miex.cbSize = sizeof(MONITORINFOEX);
29 GetMonitorInfo(hMon, &miex);
31 if (miex.dwFlags == DISPLAY_DEVICE_MIRRORING_DRIVER)
32 return TRUE;
34 std::vector<RECT>* pMonRects = reinterpret_cast<std::vector<RECT>*>(pData);
35 pMonRects->push_back(*lprcMonitor);
36 return TRUE;
39 std::wstring GetMonitorSetupHash()
41 std::vector<RECT> monRects;
42 EnumDisplayMonitors(0, 0, MonitorEnum, reinterpret_cast<LPARAM>(&monRects));
43 std::sort(monRects.begin(), monRects.end(),
44 [](const RECT& a, const RECT& b) -> bool {
45 if (a.left == b.left)
46 return a.top < b.top;
47 return a.left < b.left;
48 });
49 return GetHashText(monRects.data(), monRects.size() * sizeof(RECT), HashType::HashMd5);