From 124722584107ba99ac9f6f8882fa56e80eff69ba Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 3 Dec 2012 13:28:08 +0100 Subject: [PATCH] user32: Refresh the desktop when the wallpaper is changed. --- dlls/user32/controls.h | 2 +- dlls/user32/desktop.c | 17 +++++++---------- dlls/user32/sysparams.c | 26 +++++++++++++++++++++----- programs/explorer/desktop.c | 7 ++++++- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/dlls/user32/controls.h b/dlls/user32/controls.h index 6bd946b6673..e168f16015d 100644 --- a/dlls/user32/controls.h +++ b/dlls/user32/controls.h @@ -148,7 +148,7 @@ extern struct dce *set_class_dce( struct tagCLASS *class, struct dce *dce ) DECL extern HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType ) DECLSPEC_HIDDEN; /* desktop */ -extern BOOL DESKTOP_SetPattern( LPCWSTR pattern ) DECLSPEC_HIDDEN; +extern BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern ) DECLSPEC_HIDDEN; /* icon title */ extern HWND ICONTITLE_Create( HWND hwnd ) DECLSPEC_HIDDEN; diff --git a/dlls/user32/desktop.c b/dlls/user32/desktop.c index ddf812ad449..2204b77c330 100644 --- a/dlls/user32/desktop.c +++ b/dlls/user32/desktop.c @@ -56,12 +56,10 @@ const struct builtin_class_descr DESKTOP_builtin_class = /*********************************************************************** * DESKTOP_LoadBitmap */ -static HBITMAP DESKTOP_LoadBitmap(void) +static HBITMAP DESKTOP_LoadBitmap( const WCHAR *filename ) { HBITMAP hbitmap; - WCHAR filename[MAX_PATH]; - if (!SystemParametersInfoW( SPI_GETDESKWALLPAPER, MAX_PATH, filename, 0 )) return 0; if (!filename[0]) return 0; hbitmap = LoadImageW( 0, filename, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION | LR_LOADFROMFILE ); if (!hbitmap) @@ -78,9 +76,9 @@ static HBITMAP DESKTOP_LoadBitmap(void) /*********************************************************************** * init_wallpaper */ -static void init_wallpaper(void) +static void init_wallpaper( const WCHAR *wallpaper ) { - HBITMAP hbitmap = DESKTOP_LoadBitmap(); + HBITMAP hbitmap = DESKTOP_LoadBitmap( wallpaper ); if (hbitmapWallPaper) DeleteObject( hbitmapWallPaper ); hbitmapWallPaper = hbitmap; @@ -172,11 +170,9 @@ BOOL WINAPI SetDeskWallPaper( LPCSTR filename ) /*********************************************************************** - * DESKTOP_SetPattern - * - * Set the desktop pattern. + * update_wallpaper */ -BOOL DESKTOP_SetPattern( LPCWSTR pattern ) +BOOL update_wallpaper( const WCHAR *wallpaper, const WCHAR *pattern ) { int pat[8]; @@ -201,6 +197,7 @@ BOOL DESKTOP_SetPattern( LPCWSTR pattern ) DeleteObject( hbitmap ); } } - init_wallpaper(); + init_wallpaper( wallpaper ); + RedrawWindow( GetDesktopWindow(), 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_NOCHILDREN ); return TRUE; } diff --git a/dlls/user32/sysparams.c b/dlls/user32/sysparams.c index 895b4eb0933..3e9a6395026 100644 --- a/dlls/user32/sysparams.c +++ b/dlls/user32/sysparams.c @@ -1293,6 +1293,7 @@ static union sysparam_all_entry * const default_entries[] = (union sysparam_all_entry *)&entry_CAPTIONHEIGHT, (union sysparam_all_entry *)&entry_CAPTIONWIDTH, (union sysparam_all_entry *)&entry_CARETWIDTH, + (union sysparam_all_entry *)&entry_DESKWALLPAPER, (union sysparam_all_entry *)&entry_DOUBLECLICKTIME, (union sysparam_all_entry *)&entry_DOUBLECLKHEIGHT, (union sysparam_all_entry *)&entry_DOUBLECLKWIDTH, @@ -1374,6 +1375,23 @@ void SYSPARAMS_Init(void) } } +static BOOL update_desktop_wallpaper(void) +{ + DWORD pid; + + if (GetWindowThreadProcessId( GetDesktopWindow(), &pid ) && pid == GetCurrentProcessId()) + { + WCHAR wallpaper[MAX_PATH], pattern[256]; + + entry_DESKWALLPAPER.hdr.loaded = entry_DESKPATTERN.hdr.loaded = FALSE; + if (get_entry( &entry_DESKWALLPAPER, MAX_PATH, wallpaper ) && + get_entry( &entry_DESKPATTERN, 256, pattern )) + update_wallpaper( wallpaper, pattern ); + } + else SendMessageW( GetDesktopWindow(), WM_SETTINGCHANGE, SPI_SETDESKWALLPAPER, 0 ); + return TRUE; +} + /*********************************************************************** * SystemParametersInfoW (USER32.@) * @@ -1484,14 +1502,12 @@ BOOL WINAPI SystemParametersInfoW( UINT uiAction, UINT uiParam, ret = set_entry( &entry_GRIDGRANULARITY, uiParam, pvParam, fWinIni ); break; case SPI_SETDESKWALLPAPER: - ret = set_entry( &entry_DESKWALLPAPER, uiParam, pvParam, fWinIni ); + if (!pvParam || set_entry( &entry_DESKWALLPAPER, uiParam, pvParam, fWinIni )) + ret = update_desktop_wallpaper(); break; case SPI_SETDESKPATTERN: if (!pvParam || set_entry( &entry_DESKPATTERN, uiParam, pvParam, fWinIni )) - { - WCHAR buf[256]; - ret = get_entry( &entry_DESKPATTERN, 256, buf ) && DESKTOP_SetPattern( buf ); - } + ret = update_desktop_wallpaper(); break; case SPI_GETKEYBOARDDELAY: ret = get_entry( &entry_KEYBOARDDELAY, uiParam, pvParam ); diff --git a/programs/explorer/desktop.c b/programs/explorer/desktop.c index fdb966f5dbb..12888d84f2f 100644 --- a/programs/explorer/desktop.c +++ b/programs/explorer/desktop.c @@ -85,6 +85,11 @@ static LRESULT WINAPI desktop_wnd_proc( HWND hwnd, UINT message, WPARAM wp, LPAR if (!using_root) PaintDesktop( (HDC)wp ); return TRUE; + case WM_SETTINGCHANGE: + if (wp == SPI_SETDESKWALLPAPER) + SystemParametersInfoW( SPI_SETDESKWALLPAPER, 0, NULL, FALSE ); + return 0; + case WM_PAINT: { PAINTSTRUCT ps; @@ -311,7 +316,7 @@ void manage_desktop( WCHAR *arg ) SetWindowLongPtrW( hwnd, GWLP_WNDPROC, (LONG_PTR)desktop_wnd_proc ); SendMessageW( hwnd, WM_SETICON, ICON_BIG, (LPARAM)LoadIconW( 0, MAKEINTRESOURCEW(OIC_WINLOGO))); if (name) set_desktop_window_title( hwnd, name ); - SystemParametersInfoA( SPI_SETDESKPATTERN, -1, NULL, FALSE ); + SystemParametersInfoW( SPI_SETDESKWALLPAPER, 0, NULL, FALSE ); ClipCursor( NULL ); initialize_display_settings( hwnd ); initialize_appbar();