Jump to content

Sending WM_SETTINGCHANGE message to refresh desktop


Recommended Posts

Hello everybody, this is my first post and I'm quite new to the world of AutoIt.

I already manage to change programmatically my desktop background via this one-liner:

DllCall("user32.dll", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $CmdLine[1], "int", 0)

(via drag 'n' drop of the desired wallpaper onto the compiled script).

However, this code does even too much for my needs. In fact I have another software that changes the desktop but, for some unknown-to-me reasons, fails to send the WM_SETTINGCHANGE message (I can see the key HKCU\Control Panel\Desktop\Wallpaper getting updated in fact, by the way).

So I ask you: how can I write a simple script that sends this message and thus triggers the wallpaper refresh? And will it work or the first script is the only "real"/"correct" way to proceed programmatically?

I tried this but it doesn't work:

#include-once

Global $MAX_VALUE_NAME = 1024
Global $HWND_BROADCAST = 0xffff
Global $WM_SETTINGCHANGE = 0x001A
Global $SMTO_ABORTIFHUNG = 0x0002
Global $SMTO_NORMAL = 0x0000
Global $MSG_TIMEOUT = 5000

DllCall("user32.dll", "lresult", "SendMessageTimeoutW", _
"hwnd", $HWND_BROADCAST, _
"dword", $WM_SETTINGCHANGE, _
"ptr", 0, _
"wstr", "Environment", _
"dword", $SMTO_ABORTIFHUNG, _
"dword", $MSG_TIMEOUT, _
"dword_ptr*", 0)

Many thanks in advance to whomever will help me!

Link to comment
Share on other sites

Ok, that works fine, but is a full-fledged script well beyond my needs, as I wrote above even that one-liner does too much for me.

I'm just interested in sending the WM_SETTINGCHANGE message. Unfortunately these pages http://msdn.microsoft.com/en-us/library/windows/desktop/ms644952(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/ms725497(v=vs.85).aspx are a bit too technical for me...

Edited by Marcooo
Link to comment
Share on other sites

I see I could use the function SendMessage function, too. However this code does nothing:

DllCall("user32.dll", "lresult", "SendMessage", _
"int", 0xffff, _
"int", 0x001a, _
"int", 0x0014, _
"str", "HKCUControl Panel")

0xffff is for broadcasting the message to every window, 0x001a stands for WM_SETTINGCHANGE, 0x0014 is the code for spi_setdeskwallpaper. The taskbar in Windows 7 flickers a little but the wallpaper doesn't change, why?

Link to comment
Share on other sites

I tried checking the error code with this:

$aResult = DllCall("user32.dll", "int", "PostMessage", "int", 0xffff, "int", 0x001a, "int", 0x0014, "str", "HKCUControl PanelDesktop")



msgbox(0,"",$aResult[0])

and it returns 0.

So I should assume that WM_SETTINGCHANGE is really sent, yet it doesn't produce the effect I expect?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...