-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathwinutlis.cpp
97 lines (76 loc) · 3.58 KB
/
winutlis.cpp
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
/***************************************************************************
* Copyright (C) 2011 by Nicolae Ghimbovschi *
* nicolae.ghimbovschi@gmail.com *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; version 3 of the License. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
#include "winutlis.h"
#include <windows.h>
#define DWM_BB_ENABLE 0x00000001 // fEnable has been specified
typedef struct _DWM_BLURBEHIND
{
DWORD dwFlags;
BOOL fEnable;
HRGN hRgnBlur;
BOOL fTransitionOnMaximized;
} DWM_BLURBEHIND, *PDWM_BLURBEHIND;
typedef struct _MARGINS
{
int cxLeftWidth; // width of left border that retains its size
int cxRightWidth; // width of right border that retains its size
int cyTopHeight; // height of top border that retains its size
int cyBottomHeight; // height of bottom border that retains its size
} MARGINS, *PMARGINS;
extern "C"
{
typedef HRESULT (WINAPI *t_DwmEnableBlurBehindWindow)(HWND hWnd, const DWM_BLURBEHIND* pBlurBehind);
typedef HRESULT (WINAPI *t_DwmExtendFrameIntoClientArea)(HWND hwnd, const MARGINS *pMarInset);
}
void DwmExtendFrameIntoClientArea(HWND hwnd, const MARGINS *pMarInset) {
HMODULE shell;
shell = LoadLibrary(L"dwmapi.dll");
if (shell) {
t_DwmExtendFrameIntoClientArea set_window_frame_into_client_area = reinterpret_cast<t_DwmExtendFrameIntoClientArea>(GetProcAddress (shell, "DwmExtendFrameIntoClientArea"));
set_window_frame_into_client_area(hwnd, pMarInset);
FreeLibrary (shell);
}
}
void DwmEnableBlurBehindWindow(HWND hwnd, const DWM_BLURBEHIND* pBlurBehind) {
HMODULE shell;
shell = LoadLibrary(L"dwmapi.dll");
if (shell) {
t_DwmEnableBlurBehindWindow set_window_blur = reinterpret_cast<t_DwmEnableBlurBehindWindow>(GetProcAddress (shell, "DwmEnableBlurBehindWindow"));
set_window_blur(hwnd, pBlurBehind);
FreeLibrary (shell);
}
}
void ExtendFrameIntoClientArea(QWidget* widget) {
MARGINS margins = {-1};
DwmExtendFrameIntoClientArea(widget->winId(), &margins);
}
long EnableBlurBehindWidget(QWidget* widget, bool enable)
{
HWND hwnd = widget->winId();
HRESULT hr = S_OK;
widget->setAttribute(Qt::WA_TranslucentBackground, enable);
widget->setAttribute(Qt::WA_NoSystemBackground, enable);
// Create and populate the Blur Behind structure
DWM_BLURBEHIND bb = {0};
bb.dwFlags = DWM_BB_ENABLE;
bb.fEnable = enable;
bb.hRgnBlur = NULL;
DwmEnableBlurBehindWindow(hwnd, &bb);
return hr;
}