VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/platform/win/VBoxUtils-win.cpp

Last change on this file was 99837, checked in by vboxsync, 12 months ago

FE/Qt: bugref:10450: A bit of missed Qt includes in Win utils; They are no more auto-included by the Qt itself.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.1 KB
Line 
1/* $Id: VBoxUtils-win.cpp 99837 2023-05-18 10:03:39Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - Declarations of utility classes and functions for handling Windows specific tasks.
4 */
5
6/*
7 * Copyright (C) 2010-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QList>
30#include <QRect>
31
32/* GUI includes: */
33#include "VBoxUtils-win.h"
34
35
36/** Namespace for native window sub-system functions. */
37namespace NativeWindowSubsystem
38{
39 /** Enumerates visible always-on-top (top-most) windows. */
40 BOOL CALLBACK EnumWindowsProc(HWND hWnd, LPARAM lParam) RT_NOTHROW_PROTO;
41 /** Contains visible top-most-window rectangles. */
42 QList<QRect> topMostRects;
43}
44
45BOOL CALLBACK NativeWindowSubsystem::EnumWindowsProc(HWND hWnd, LPARAM) RT_NOTHROW_DEF
46{
47 /* Ignore NULL HWNDs: */
48 if (!hWnd)
49 return TRUE;
50
51 /* Ignore hidden windows: */
52 if (!IsWindowVisible(hWnd))
53 return TRUE;
54
55 /* Get window style: */
56 LONG uStyle = GetWindowLong(hWnd, GWL_STYLE);
57 /* Ignore minimized windows: */
58 if (uStyle & WS_MINIMIZE)
59 return TRUE;
60
61 /* Get extended window style: */
62 LONG uExtendedStyle = GetWindowLong(hWnd, GWL_EXSTYLE);
63 /* Ignore non-top-most windows: */
64 if (!(uExtendedStyle & WS_EX_TOPMOST))
65 return TRUE;
66
67 /* Get that window rectangle: */
68 RECT rect;
69 GetWindowRect(hWnd, &rect);
70 topMostRects << QRect(QPoint(rect.left, rect.top), QPoint(rect.right - 1, rect.bottom - 1));
71
72 /* Proceed to the next window: */
73 return TRUE;
74}
75
76const QRegion NativeWindowSubsystem::areaCoveredByTopMostWindows()
77{
78 /* Prepare the top-most region: */
79 QRegion topMostRegion;
80 /* Initialize the list of the top-most rectangles: */
81 topMostRects.clear();
82 /* Populate the list of top-most rectangles: */
83 EnumWindows((WNDENUMPROC)EnumWindowsProc, 0);
84 /* Update the top-most region with top-most rectangles: */
85 for (int iRectIndex = 0; iRectIndex < topMostRects.size(); ++iRectIndex)
86 topMostRegion += topMostRects[iRectIndex];
87 /* Return top-most region: */
88 return topMostRegion;
89}
90
91const void NativeWindowSubsystem::setScreenSaverActive(BOOL fDisableScreenSaver)
92{
93 BOOL fIsActive;
94 SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &fIsActive, 0);
95 if (fIsActive == !fDisableScreenSaver)
96 return;
97 //printf("before %d\n", fIsActive);
98
99 SystemParametersInfo(SPI_SETSCREENSAVEACTIVE, !fDisableScreenSaver, NULL, 0);
100
101 SystemParametersInfo(SPI_GETSCREENSAVEACTIVE, 0, &fIsActive, 0);
102 /*if (fIsActive == !fDisableScreenSaver)
103 printf("success %d %d\n", fIsActive, fDisableScreenSaver);
104*/
105}
106
107BOOL NativeWindowSubsystem::ShutdownBlockReasonCreateAPI(HWND hWnd, LPCWSTR pwszReason)
108{
109 BOOL fResult = FALSE;
110 typedef BOOL(WINAPI *PFNSHUTDOWNBLOCKREASONCREATE)(HWND hWnd, LPCWSTR pwszReason);
111
112 PFNSHUTDOWNBLOCKREASONCREATE pfn = (PFNSHUTDOWNBLOCKREASONCREATE)GetProcAddress(
113 GetModuleHandle(L"User32.dll"), "ShutdownBlockReasonCreate");
114 _ASSERTE(pfn);
115 if (pfn)
116 fResult = pfn(hWnd, pwszReason);
117 return fResult;
118}
119
120bool NativeWindowSubsystem::WinActivateWindow(WId wId, bool)
121{
122 bool fResult = true;
123 HWND handle = (HWND)wId;
124
125 if (IsIconic(handle))
126 fResult &= !!ShowWindow(handle, SW_RESTORE);
127 else if (!IsWindowVisible(handle))
128 fResult &= !!ShowWindow(handle, SW_SHOW);
129
130 fResult &= !!SetForegroundWindow(handle);
131 return fResult;
132}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use