CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/external/source/vncdll/winvnc/WallpaperUtils.cpp
Views: 11780
1
// This file is part of the VNC system.
2
//
3
// The VNC system is free software; you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation; either version 2 of the License, or
6
// (at your option) any later version.
7
//
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
12
//
13
// You should have received a copy of the GNU General Public License
14
// along with this program; if not, write to the Free Software
15
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16
// USA.
17
//
18
// TightVNC distribution homepage on the Web: http://www.tightvnc.com/
19
//
20
// If the source code for the VNC system is not available from the place
21
// whence you received this file, check http://www.uk.research.att.com/vnc or contact
22
// the authors on [email protected] for information on obtaining it.
23
24
#include "WallpaperUtils.h"
25
26
WallpaperUtils::WallpaperUtils()
27
{
28
m_restore_ActiveDesktop = false;
29
m_restore_wallpaper = false;
30
}
31
32
void
33
WallpaperUtils::KillActiveDesktop()
34
{
35
// Contact Active Desktop if possible
36
HRESULT result;
37
IActiveDesktop* active_desktop = 0;
38
result = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
39
IID_IActiveDesktop, (void**)&active_desktop);
40
if (result != S_OK) {
41
return;
42
}
43
44
// Get Active Desktop options
45
COMPONENTSOPT options;
46
options.dwSize = sizeof(options);
47
result = active_desktop->GetDesktopItemOptions(&options, 0);
48
if (result != S_OK) {
49
active_desktop->Release();
50
return;
51
}
52
53
// Disable if currently active
54
m_restore_ActiveDesktop = (options.fActiveDesktop != 0);
55
if (options.fActiveDesktop) {
56
options.fActiveDesktop = FALSE;
57
result = active_desktop->SetDesktopItemOptions(&options, 0);
58
if (result != S_OK) {
59
active_desktop->Release();
60
return;
61
}
62
}
63
active_desktop->ApplyChanges(AD_APPLY_REFRESH);
64
active_desktop->Release();
65
}
66
67
void
68
WallpaperUtils::KillWallpaper()
69
{
70
if (!m_restore_wallpaper) {
71
// Tell all applications that there is no wallpaper
72
// Note that this doesn't change the wallpaper registry setting!
73
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "", SPIF_SENDCHANGE);
74
m_restore_wallpaper = true;
75
}
76
77
CoInitialize(NULL);
78
KillActiveDesktop();
79
CoUninitialize();
80
}
81
82
void
83
WallpaperUtils::RestoreActiveDesktop()
84
{
85
// Contact Active Desktop if possible
86
HRESULT result;
87
IActiveDesktop* active_desktop = 0;
88
result = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,
89
IID_IActiveDesktop, (void**)&active_desktop);
90
if (result != S_OK) {
91
return;
92
}
93
94
// Get Active Desktop options
95
COMPONENTSOPT options;
96
options.dwSize = sizeof(options);
97
result = active_desktop->GetDesktopItemOptions(&options, 0);
98
if (result != S_OK) {
99
active_desktop->Release();
100
return;
101
}
102
103
// Re-enable if previously disabled
104
if (m_restore_ActiveDesktop) {
105
m_restore_ActiveDesktop = false;
106
options.fActiveDesktop = TRUE;
107
result = active_desktop->SetDesktopItemOptions(&options, 0);
108
if (result != S_OK) {
109
active_desktop->Release();
110
return;
111
}
112
}
113
114
active_desktop->ApplyChanges(AD_APPLY_REFRESH);
115
active_desktop->Release();
116
}
117
118
void
119
WallpaperUtils::RestoreWallpaper()
120
{
121
CoInitialize(NULL);
122
RestoreActiveDesktop();
123
CoUninitialize();
124
125
if (m_restore_wallpaper) {
126
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);
127
m_restore_wallpaper = false;
128
}
129
}
130
131
132