Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions nDesk/DesktopPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ DesktopPainter::DesktopPainter(HWND hWnd) : Window(hWnd, L"nDesk", g_pClickHandl

nCore::System::RegisterWindow(L"nDesk", this);
UpdateWallpaper(true);

//Create the notification for wallpaper change
hWallpaperEvent = CreateEvent(NULL, false, false, NULL);
RegOpenKeyEx(HKEY_CURRENT_USER, L"Control Panel\\Desktop", 0, KEY_NOTIFY, &hWallpaperKey);
RegNotifyChangeKeyValue(hWallpaperKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, hWallpaperEvent, TRUE);
}

/// <summary>
Expand All @@ -78,6 +83,12 @@ DesktopPainter::~DesktopPainter() {
if (m_TransitionEffect) {
delete m_TransitionEffect;
}

//Close the wallpaper event
CloseHandle(hWallpaperEvent);

//Close the wallpaper registry key
RegCloseKey(hWallpaperKey);
}

/// <summary>
Expand Down Expand Up @@ -328,13 +339,28 @@ void DesktopPainter::PaintComposite() {
/// Handles certain window messages.
/// </summary>
LRESULT DesktopPainter::HandleMessage(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {

//Check if the wallpaper registry has been changed
if (WaitForSingleObject(hWallpaperEvent, 0) == WAIT_OBJECT_0)
{
//Fetch the new wallpaper
UpdateWallpaper();

//Force window to redraw
this->Repaint();

//RegNotifyChangeKeyValue() expires after the event has changed state
RegNotifyChangeKeyValue(hWallpaperKey, FALSE, REG_NOTIFY_CHANGE_LAST_SET, hWallpaperEvent, TRUE);
}

switch (uMsg) {
case WM_ERASEBKGND:
return 1;

case WM_PAINT:
{
if (!mDontRenderWallpaper) {

UpdateLock lock(this);

bool inAnimation = false;
Expand Down
4 changes: 4 additions & 0 deletions nDesk/DesktopPainter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,8 @@ class DesktopPainter : protected Window
// If on, every window will be repainted when the wallpaper is changed instead of just the
// desktop background. Fixes issues with other modules (xModules).
bool m_bInvalidateAllOnUpdate;

//Event to check if Desktop Wallpaper has been changed
HANDLE hWallpaperEvent;
HKEY hWallpaperKey;
};