QWindowKit  1.5.1.0
Cross-platform window customization framework
Loading...
Searching...
No Matches
qwindowkit_windows.h
1// Copyright (C) 2023-present Stdware Collections (https://www.github.com/stdware)
2// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao)
3// SPDX-License-Identifier: Apache-2.0
4
5#ifndef QWINDOWKIT_WINDOWS_H
6#define QWINDOWKIT_WINDOWS_H
7
8#ifndef _USER32_
9# define _USER32_
10#endif
11
12#ifndef _DWMAPI_
13# define _DWMAPI_
14#endif
15
16#include <QtCore/qt_windows.h>
17#include <QtCore/qglobal.h>
18
19#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
20# include <QtCore/private/qwinregistry_p.h>
21#endif
22
23#include <QWKCore/qwkglobal.h>
24
25#ifndef GET_X_LPARAM
26# define GET_X_LPARAM(lp) (static_cast<int>(static_cast<short>(LOWORD(lp))))
27#endif
28
29#ifndef GET_Y_LPARAM
30# define GET_Y_LPARAM(lp) (static_cast<int>(static_cast<short>(HIWORD(lp))))
31#endif
32
33#ifndef RECT_WIDTH
34# define RECT_WIDTH(rect) ((rect).right - (rect).left)
35#endif
36
37#ifndef RECT_HEIGHT
38# define RECT_HEIGHT(rect) ((rect).bottom - (rect).top)
39#endif
40
41#ifndef USER_DEFAULT_SCREEN_DPI
42# define USER_DEFAULT_SCREEN_DPI (96)
43#endif
44
45// Maybe undocumented Windows messages
46// https://github.com/tinysec/public/blob/master/win32k/MessageTable.md
47// https://ulib.sourceforge.io/doxy/a00239.html
48#ifndef WM_UAHDESTROYWINDOW
49# define WM_UAHDESTROYWINDOW (0x0090)
50#endif
51
52#ifndef WM_UNREGISTER_WINDOW_SERVICES
53# define WM_UNREGISTER_WINDOW_SERVICES (0x0272)
54#endif
55
56#ifndef WM_NCUAHDRAWCAPTION
57# define WM_NCUAHDRAWCAPTION (0x00AE)
58#endif
59
60#ifndef WM_NCUAHDRAWFRAME
61# define WM_NCUAHDRAWFRAME (0x00AF)
62#endif
63
64// Required missing messages under windows 7
65#ifndef WM_NCPOINTERUPDATE
66# define WM_NCPOINTERUPDATE (0x0241)
67#endif
68
69#ifndef WM_NCPOINTERDOWN
70# define WM_NCPOINTERDOWN (0x0242)
71#endif
72
73#ifndef WM_NCPOINTERUP
74# define WM_NCPOINTERUP (0x0243)
75#endif
76
77using QWK_OSVERSIONINFOW = struct _QWK_OSVERSIONINFOW {
78 DWORD dwOSVersionInfoSize;
79 DWORD dwMajorVersion;
80 DWORD dwMinorVersion;
81 DWORD dwBuildNumber;
82 DWORD dwPlatformId;
83 wchar_t szCSDVersion[128];
84};
85
86namespace QWK {
87
88 namespace Private {
89
90 QWK_CORE_EXPORT QWK_OSVERSIONINFOW GetRealOSVersion();
91
92 inline bool IsWindows1122H2OrGreater_Real() {
93 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
94 return (rovi.dwMajorVersion > 10) ||
95 (rovi.dwMajorVersion == 10 &&
96 (rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 22621));
97 }
98
99 inline bool IsWindows11OrGreater_Real() {
100 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
101 return (rovi.dwMajorVersion > 10) ||
102 (rovi.dwMajorVersion == 10 &&
103 (rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 22000));
104 }
105
106 inline bool IsWindows1020H1OrGreater_Real() {
107 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
108 return (rovi.dwMajorVersion > 10) ||
109 (rovi.dwMajorVersion == 10 &&
110 (rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 19041));
111 }
112
113 inline bool IsWindows102004OrGreater_Real() {
114 return IsWindows1020H1OrGreater_Real();
115 }
116
117 inline bool IsWindows101903OrGreater_Real() {
118 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
119 return (rovi.dwMajorVersion > 10) ||
120 (rovi.dwMajorVersion == 10 &&
121 (rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 18362));
122 }
123
124 inline bool IsWindows1019H1OrGreater_Real() {
125 return IsWindows101903OrGreater_Real();
126 }
127
128 inline bool IsWindows101809OrGreater_Real() {
129 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
130 return (rovi.dwMajorVersion > 10) ||
131 (rovi.dwMajorVersion == 10 &&
132 (rovi.dwMinorVersion > 0 || rovi.dwBuildNumber >= 17763));
133 }
134
135 inline bool IsWindows10RS5OrGreater_Real() {
136 return IsWindows101809OrGreater_Real();
137 }
138
139 inline bool IsWindows10OrGreater_Real() {
140 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
141 return rovi.dwMajorVersion >= 10;
142 }
143
144 inline bool IsWindows8Point1OrGreater_Real() {
145 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
146 return (rovi.dwMajorVersion > 6) ||
147 (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion >= 3);
148 }
149
150 inline bool IsWindows8OrGreater_Real() {
151 QWK_OSVERSIONINFOW rovi = GetRealOSVersion();
152 return (rovi.dwMajorVersion > 6) ||
153 (rovi.dwMajorVersion == 6 && rovi.dwMinorVersion >= 2);
154 }
155
156 inline bool IsWindows10Only_Real() {
157 return IsWindows10OrGreater_Real() && !IsWindows11OrGreater_Real();
158 }
159
160 }
161
162 //
163 // Registry Helpers
164 //
165
166#if QT_VERSION < QT_VERSION_CHECK(5, 14, 0)
167 class QWK_CORE_EXPORT WindowsRegistryKey {
168 public:
169 WindowsRegistryKey(HKEY parentHandle, QStringView subKey, REGSAM permissions = KEY_READ,
170 REGSAM access = 0);
171
172 ~WindowsRegistryKey();
173
174 inline bool isValid() const;
175
176 void close();
177 QString stringValue(QStringView subKey) const;
178 std::pair<DWORD, bool> dwordValue(QStringView subKey) const;
179
180 private:
181 HKEY m_key;
182
183 Q_DISABLE_COPY(WindowsRegistryKey)
184 };
185
186 inline bool WindowsRegistryKey::isValid() const {
187 return m_key != nullptr;
188 }
189#elif QT_VERSION < QT_VERSION_CHECK(6, 8, 1)
190 using WindowsRegistryKey = QWinRegistryKey;
191#else
192 class WindowsRegistryKey : public QWinRegistryKey {
193#if QT_VERSION >= QT_VERSION_CHECK(6, 10, 1)
194 using SubKeyType = const wchar_t*;
195#else
196 using SubKeyType = QStringView;
197#endif
198 public:
199 WindowsRegistryKey(HKEY parentHandle, SubKeyType subKey,
200 REGSAM permissions = KEY_READ, REGSAM access = 0)
201 : QWinRegistryKey(parentHandle, subKey, permissions, access) {
202 }
203
204 inline std::pair<DWORD, bool> dwordValue(SubKeyType subKey) const;
205 };
206
207 inline std::pair<DWORD, bool> WindowsRegistryKey::dwordValue(SubKeyType subKey) const {
208 const auto val = value<DWORD>(subKey);
209 if (!val) {
210 return {0, false};
211 }
212 return {val.value(), true};
213 }
214#endif
215
216 //
217 // Version Helpers
218 //
219
220 inline bool isWin8OrGreater() {
221 static const bool result = Private::IsWindows8OrGreater_Real();
222 return result;
223 }
224
225 inline bool isWin8Point1OrGreater() {
226 static const bool result = Private::IsWindows8Point1OrGreater_Real();
227 return result;
228 }
229
230 inline bool isWin10OrGreater() {
231 static const bool result = Private::IsWindows10OrGreater_Real();
232 return result;
233 }
234
235 inline bool isWin101809OrGreater() {
236 static const bool result = Private::IsWindows101809OrGreater_Real();
237 return result;
238 }
239
240 inline bool isWin10RS5OrGreater() {
241 return isWin101809OrGreater();
242 }
243
244 inline bool isWin101903OrGreater() {
245 static const bool result = Private::IsWindows101903OrGreater_Real();
246 return result;
247 }
248
249 inline bool isWin1019H1OrGreater() {
250 return isWin101903OrGreater();
251 }
252
253 inline bool isWin1020H1OrGreater() {
254 static const bool result = Private::IsWindows1020H1OrGreater_Real();
255 return result;
256 }
257
258 inline bool isWin102004OrGreater() {
259 return isWin1020H1OrGreater();
260 }
261
262 inline bool isWin11OrGreater() {
263 static const bool result = Private::IsWindows11OrGreater_Real();
264 return result;
265 }
266
267 inline bool isWin1122H2OrGreater() {
268 static const bool result = Private::IsWindows1122H2OrGreater_Real();
269 return result;
270 }
271
272 inline bool isWin10Only() {
273 static const bool result = Private::IsWindows10Only_Real();
274 return result;
275 };
276
277 //
278 // Native Event Helpers
279 //
280
281 inline bool isImmersiveColorSetChange(WPARAM wParam, LPARAM lParam) {
282 return !wParam && lParam &&
283 std::wcscmp(reinterpret_cast<LPCWSTR>(lParam), L"ImmersiveColorSet") == 0;
284 }
285
286}
287
288#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
289Q_DECLARE_METATYPE(QMargins)
290#endif
291
292#endif // QWINDOWKIT_WINDOWS_H
QWindowKit namespace.
Definition abstractwindowcontext.cpp:13