Jump to content
Sign in to follow this  
phew

Wallpaper Changing

Recommended Posts

phew

hi,

i've found http://www.autoitscript.com/forum/index.php?showtopic=5798

which says:

RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
  DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)

would change the wallpaper, but when i execute my script

_ChangeWallpaper()

Func _ChangeWallpaper() 
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', "C:\Dokumente und Einstellungen\phew\Desktop\hello.jpg")
    DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", "C:\Dokumente und Einstellungen\phew\Desktop\hello.jpg", "int", 0)
EndFunc

the desktop background just becomes light-blue but the new wallpaper is not set. (on rightmouse (desktop) -> properties the wallpaper is previewed but finally its not changed on the desktop!)

someone can help? :)

Share this post


Link to post
Share on other sites
SandelPerieanu

hi,

i've found http://www.autoitscript.com/forum/index.php?showtopic=5798

which says:

RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', $sFile)
  DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", $sFile, "int", 0)

would change the wallpaper, but when i execute my script

_ChangeWallpaper()

Func _ChangeWallpaper() 
    RegWrite('HKCU\Control Panel\Desktop', 'Wallpaper', 'reg_sz', "C:\Dokumente und Einstellungen\phew\Desktop\hello.jpg")
    DllCall("user32", "int", "SystemParametersInfo", "int", 20, "int", 0, "str", "C:\Dokumente und Einstellungen\phew\Desktop\hello.jpg", "int", 0)
EndFunc

the desktop background just becomes light-blue but the new wallpaper is not set. (on rightmouse (desktop) -> properties the wallpaper is previewed but finally its not changed on the desktop!)

someone can help? :)

only *.bmp files

Share this post


Link to post
Share on other sites
phew

thank you very much :]

my bad, didn't read the other topic carefully

but is there any possibility to use .JPG files, too?

Share this post


Link to post
Share on other sites
SandelPerieanu

thank you very much :]

my bad, didn't read the other topic carefully

but is there any possibility to use .JPG files, too?

try this with auto3lib.exe

Share this post


Link to post
Share on other sites
phew

okay i'll do, thank you :)

Share this post


Link to post
Share on other sites
SandelPerieanu

okay i'll do, thank you :)

use this

#Include <A3LGDIPlus.au3>
Opt("MustDeclareVars", 1)
Global $sImage, $hImage, $sCLSID
$sImage = @ScriptDir & '\Image.jpg'
_GDIP_StartUp()
$hImage = _GDIP_ImageLoadFromFile($sImage)
$sCLSID = _GDIP_EncodersGetCLSID("BMP")
_GDIP_ImageSaveToFileEx($hImage, @ScriptDir & '\Image.bmp', $sCLSID))
_GDIP_ShutDown()

to convert *.jpg into *.bmp

Share this post


Link to post
Share on other sites
Achilles

All together it looks like this:

Func _ChangeDesktopBackground($sFile, $iPosition = 3)
    Local $sCLSID, $tBuffer, $hImage, $sTemp

; Convert image to BMP image
    _GDIP_Startup()
    $hImage = _GDIP_Image($sFile)
    $sCLSID = _GDIP_EncodersGetCLSID('BMP')
    $sTemp  = _Str_ChangeFileExt($sFile, '.bmp')
    _GDIP_ImageSaveToFile($hImage, $sTemp)
    _GDIP_ImageDispose($hImage)
    _GDIP_Shutdown()

; Set wallpaper position
    Switch $iPosition
        Case 1; Tiled
            RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper' , 'reg_sz', '1')
            RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
        Case 2; Centered
            RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper' , 'reg_sz', '0')
            RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '0')
        Case 3; Stretched
            RegWrite('HKCU\Control Panel\Desktop', 'TileWallpaper' , 'reg_sz', '0')
            RegWrite('HKCU\Control Panel\Desktop', 'WallpaperStyle', 'reg_sz', '2')
    EndSwitch

; Set wallpaper
    $tBuffer = DllStructCreate("char Text[" & StringLen($sTemp) + 1 & "]")
    DllStructSetData($tBuffer, "Text", $sTemp)
    _API_SystemParametersInfo($SPI_SETDESKWALLPAPER, 0, DllStructGetPtr($tBuffer), BitOR($SPIF_UPDATEINIFILE, $SPIF_SENDCHANGE))
EndFunc

My Programs[list][*]Knight Media Player[*]Multiple Desktops[*]Daily Comics[*]Journal[/list]

Share this post


Link to post
Share on other sites
Der_Andi

Does Windows XP also convert pictures in bitmap-format when i change my wallpaper?

Share this post


Link to post
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
Sign in to follow this  

×