Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/external/source/vncdll/winvnc/WallpaperUtils.cpp
Views: 11780
// This file is part of the VNC system.1//2// The VNC system is free software; you can redistribute it and/or modify3// it under the terms of the GNU General Public License as published by4// the Free Software Foundation; either version 2 of the License, or5// (at your option) any later version.6//7// This program is distributed in the hope that it will be useful,8// but WITHOUT ANY WARRANTY; without even the implied warranty of9// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the10// GNU General Public License for more details.11//12// You should have received a copy of the GNU General Public License13// along with this program; if not, write to the Free Software14// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,15// USA.16//17// TightVNC distribution homepage on the Web: http://www.tightvnc.com/18//19// If the source code for the VNC system is not available from the place20// whence you received this file, check http://www.uk.research.att.com/vnc or contact21// the authors on [email protected] for information on obtaining it.2223#include "WallpaperUtils.h"2425WallpaperUtils::WallpaperUtils()26{27m_restore_ActiveDesktop = false;28m_restore_wallpaper = false;29}3031void32WallpaperUtils::KillActiveDesktop()33{34// Contact Active Desktop if possible35HRESULT result;36IActiveDesktop* active_desktop = 0;37result = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,38IID_IActiveDesktop, (void**)&active_desktop);39if (result != S_OK) {40return;41}4243// Get Active Desktop options44COMPONENTSOPT options;45options.dwSize = sizeof(options);46result = active_desktop->GetDesktopItemOptions(&options, 0);47if (result != S_OK) {48active_desktop->Release();49return;50}5152// Disable if currently active53m_restore_ActiveDesktop = (options.fActiveDesktop != 0);54if (options.fActiveDesktop) {55options.fActiveDesktop = FALSE;56result = active_desktop->SetDesktopItemOptions(&options, 0);57if (result != S_OK) {58active_desktop->Release();59return;60}61}62active_desktop->ApplyChanges(AD_APPLY_REFRESH);63active_desktop->Release();64}6566void67WallpaperUtils::KillWallpaper()68{69if (!m_restore_wallpaper) {70// Tell all applications that there is no wallpaper71// Note that this doesn't change the wallpaper registry setting!72SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "", SPIF_SENDCHANGE);73m_restore_wallpaper = true;74}7576CoInitialize(NULL);77KillActiveDesktop();78CoUninitialize();79}8081void82WallpaperUtils::RestoreActiveDesktop()83{84// Contact Active Desktop if possible85HRESULT result;86IActiveDesktop* active_desktop = 0;87result = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,88IID_IActiveDesktop, (void**)&active_desktop);89if (result != S_OK) {90return;91}9293// Get Active Desktop options94COMPONENTSOPT options;95options.dwSize = sizeof(options);96result = active_desktop->GetDesktopItemOptions(&options, 0);97if (result != S_OK) {98active_desktop->Release();99return;100}101102// Re-enable if previously disabled103if (m_restore_ActiveDesktop) {104m_restore_ActiveDesktop = false;105options.fActiveDesktop = TRUE;106result = active_desktop->SetDesktopItemOptions(&options, 0);107if (result != S_OK) {108active_desktop->Release();109return;110}111}112113active_desktop->ApplyChanges(AD_APPLY_REFRESH);114active_desktop->Release();115}116117void118WallpaperUtils::RestoreWallpaper()119{120CoInitialize(NULL);121RestoreActiveDesktop();122CoUninitialize();123124if (m_restore_wallpaper) {125SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, NULL, SPIF_SENDCHANGE);126m_restore_wallpaper = false;127}128}129130131132