Jump to content

Wallpaper Changing


phew
 Share

Recommended Posts

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? :)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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]
Link to comment
Share on other sites

  • 3 months later...

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...