Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qwin10helpers.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
6
7#include <QtCore/qdebug.h>
8#include <winstring.h>
9#include <roapi.h>
10
11#if defined(Q_CC_MINGW) || defined(Q_CC_CLANG)
12# define HAS_UI_VIEW_SETTINGS_INTEROP
13// Present from MSVC2015 + SDK 10 onwards
14#elif (!defined(Q_CC_MSVC) || _MSC_VER >= 1900) && WINVER >= 0x0A00
15# define HAS_UI_VIEW_SETTINGS_INTEROP
16# define HAS_UI_VIEW_SETTINGS
17#endif
18
19#include <inspectable.h>
20
21#ifdef HAS_UI_VIEW_SETTINGS
22# include <windows.ui.viewmanagement.h>
23#endif
24
25#ifdef HAS_UI_VIEW_SETTINGS_INTEROP
26# include <uiviewsettingsinterop.h>
27#endif
28
29#ifndef HAS_UI_VIEW_SETTINGS_INTEROP
30MIDL_INTERFACE("3694dbf9-8f68-44be-8ff5-195c98ede8a6")
31IUIViewSettingsInterop : public IInspectable
32{
33public:
34 virtual HRESULT STDMETHODCALLTYPE GetForWindow(
35 __RPC__in HWND hwnd,
36 __RPC__in REFIID riid,
37 __RPC__deref_out_opt void **ppv) = 0;
38};
39#endif // !HAS_UI_VIEW_SETTINGS_INTEROP
40
41#ifndef HAS_UI_VIEW_SETTINGS
42namespace ABI {
43namespace Windows {
44namespace UI {
45namespace ViewManagement {
46
48
49MIDL_INTERFACE("C63657F6-8850-470D-88F8-455E16EA2C26")
51{
52public:
54};
55
56} // namespace ViewManagement
57} // namespace UI
58} // namespace Windows
59} // namespace ABI
60#endif // HAS_UI_VIEW_SETTINGS
61
63
64// Return tablet mode, note: Does not work for GetDesktopWindow().
66{
67 bool result = false;
68
69 const wchar_t uiViewSettingsId[] = L"Windows.UI.ViewManagement.UIViewSettings";
70 HSTRING_HEADER uiViewSettingsIdRefHeader;
71 HSTRING uiViewSettingsIdHs = nullptr;
72 const auto uiViewSettingsIdLen = UINT32(sizeof(uiViewSettingsId) / sizeof(uiViewSettingsId[0]) - 1);
73 if (FAILED(WindowsCreateStringReference(uiViewSettingsId, uiViewSettingsIdLen, &uiViewSettingsIdRefHeader, &uiViewSettingsIdHs)))
74 return false;
75
76 IUIViewSettingsInterop *uiViewSettingsInterop = nullptr;
77 // __uuidof(IUIViewSettingsInterop);
78 const GUID uiViewSettingsInteropRefId = {0x3694dbf9, 0x8f68, 0x44be,{0x8f, 0xf5, 0x19, 0x5c, 0x98, 0xed, 0xe8, 0xa6}};
79
80 HRESULT hr = RoGetActivationFactory(uiViewSettingsIdHs, uiViewSettingsInteropRefId,
81 reinterpret_cast<void **>(&uiViewSettingsInterop));
82 if (FAILED(hr))
83 return false;
84
85 // __uuidof(ABI::Windows::UI::ViewManagement::IUIViewSettings);
86 const GUID uiViewSettingsRefId = {0xc63657f6, 0x8850, 0x470d,{0x88, 0xf8, 0x45, 0x5e, 0x16, 0xea, 0x2c, 0x26}};
87 ABI::Windows::UI::ViewManagement::IUIViewSettings *viewSettings = nullptr;
88 hr = uiViewSettingsInterop->GetForWindow(hwnd, uiViewSettingsRefId,
89 reinterpret_cast<void **>(&viewSettings));
90 if (SUCCEEDED(hr)) {
92 hr = viewSettings->get_UserInteractionMode(&currentMode);
93 if (SUCCEEDED(hr))
94 result = currentMode == 1; // Touch, 1
95 viewSettings->Release();
96 }
97 uiViewSettingsInterop->Release();
98 return result;
99}
100
101QT_END_NAMESPACE
QT_BEGIN_NAMESPACE bool qt_windowsIsTabletMode(HWND hwnd)