Page 1 of 1
Changing Desktop WallPaper on the fly ... i try but...
Posted: Tue Aug 17, 2004 12:36 pm
by GregBUG
i try with
SystemParametersInfo_(#SPI_SETDESKWALLPAPER, 0, "C:\Myphoto.jpg", #SPIF_UPDATEINIFILE | #SPIF_SENDWININICHANGE)
but it don't work!
i use winxp.
can you help me?
Thanks!
Ciao Gianluca.
Posted: Tue Aug 17, 2004 12:52 pm
by Max.²
Try with a bitmap (.bmp) instead of jpg...
Posted: Wed Aug 18, 2004 6:15 pm
by GregBUG
ok. now work fine. thanks!
How can i set the property stretched or "placed side by side" ?
i searched in the windows api but i can't find...
many thanks!

Posted: Thu Aug 19, 2004 2:39 pm
by Sparkie
Let me preface by saying I don't know much about the IActiveDesktop interface, but thanks to
our fellow PBer's, sec, Justin, freak, and blueznl in a related thread, I've managed to whip up some code that allows wallpaper in either .bmp or .jpg format and lets you set the Stretch, Tile, or Center options.
This code
does not remember your original wallpaper settings so make sure you have the path to your current wallpaper handy if you want to restore it as your default wallpaper.
I'm still a little fuzzy on the difference between bstr and unicode. Anyone care to clear that up for me in regards to memory allocation? It seems to work fine here on Win98fe and WinXPhome with PB 3.91, but I want to make sure I'm doing it right,
Code: Select all
#WPSTYLE_CENTER = 0
#WPSTYLE_TILE = 1
#WPSTYLE_STRETCH = 2
#WPSTYLE_MAX = 3
#AD_APPLY_SAVE = 1
#AD_APPLY_HTMLGEN = 2
#AD_APPLY_REFRESH = 4
#AD_APPLY_FORCE = 8
#AD_APPLY_ALL = #AD_APPLY_SAVE | #AD_APPLY_HTMLGEN | #AD_APPLY_REFRESH
Structure myWALLPAPEROPT
dwSize.l
dwStyle.l
EndStructure
wallpaperOptions.myWALLPAPEROPT
wallpaperOptions\dwSize = SizeOf(myWALLPAPEROPT)
CoInitialize_(0)
If CoCreateInstance_(?CLSID_ActiveDesktop,0,1,?IID_IActiveDesktop,@deskObj.IActiveDesktop) <> #S_OK
MessageRequester("Error", "Could not create object")
quit = #True
EndIf
Global wallpaperOptions, deskObj
Procedure doWallpaper(myWallpaper$)
; get option selection
If GetGadgetState(2)
wallpaperOptions\dwStyle = #WPSTYLE_TILE
ElseIf GetGadgetState(3)
wallpaperOptions\dwStyle = #WPSTYLE_STRETCH
Else
wallpaperOptions\dwStyle = #WPSTYLE_CENTER
EndIf
; allocate for wStr filename
filenameWide = AllocateMemory(Len(myWallpaper$)*2+2)
MultiByteToWideChar_(#CP_ACP, 0, @myWallpaper$, -1, filenameWide, Len(myWallpaper$)*2+2)
If deskObj\SetWallpaper(filenameWide, 0) = #S_OK
If deskObj\SetWallpaperOptions(@wallpaperOptions, 0) =#S_OK
If deskObj\ApplyChanges(#AD_APPLY_SAVE) <> #S_OK
MessageRequester("Error", "Unable to apply changes to Wallpaper.")
EndIf
EndIf
EndIf
FreeMemory(filenameWide)
ProcedureReturn 0
EndProcedure
If OpenWindow(0, 10, 10, 200, 150, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Change Wallpaper")
If CreateGadgetList(WindowID())
ButtonGadget(1, 50, 10, 100, 40, "Select Wallpaper")
OptionGadget(2, 60, 60, 100, 20, "Tile")
OptionGadget(3, 60, 90, 100, 20, "Stretch")
OptionGadget(4, 60, 120, 100, 20, "Center")
SetGadgetState(3,1)
EndIf
EndIf
Repeat
Event = WaitWindowEvent()
Select Event
Case #PB_EventGadget
Select EventGadgetID()
Case 1
wallpaper$ = Space(#MAX_PATH)
wallpaper$ = OpenFileRequester("Select Wallpaper", "c:\", "*.bmp *.jpg *.jpeg | *.bmp;*.jpg", 0 )
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 2
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 3
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 4
If wallpaper$
doWallpaper(wallpaper$)
EndIf
EndSelect
Case #PB_Event_CloseWindow
quit = #True
EndSelect
Until quit = #True
If deskObj
deskObj\release()
EndIf
CoUninitialize_()
End
DataSection
CLSID_ActiveDesktop:
Data.l $75048700
Data.w $EF1F,$11D0
Data.b $98,$88,$00,$60,$97,$DE,$AC,$F9
IID_IActiveDesktop:
Data.l $F490EB00
Data.w $1240,$11D1
Data.b $98,$88,$00,$60,$97,$DE,$AC,$F9
EndDataSection
Posted: Thu Aug 19, 2004 2:49 pm
by GregBUG
thank you!
it work fine here! (winXP PRO & WinME)

Posted: Thu Sep 20, 2007 5:03 am
by ricardo
I get invalid memory acces here in PB 4:
Code: Select all
If deskObj\SetWallpaper(filenameWide, 0) = #S_OK
Any advice?
Posted: Thu Sep 20, 2007 1:15 pm
by Kaeru Gaman
@Sparkie
would you mind pointing out the Commands that access the the Stretch, Tile, or Center options?
...I'm not interested in ActiveDesktop (gosh I hate that crap. Vade Retro, Satanas)
I had really BAD experiences with this, and I will not try a Code that may change my Desktop to "Active".
but I'm interested how to set the Options additionally to the Background Pic.
Posted: Thu Sep 20, 2007 2:45 pm
by ebs
@Kaeru,
If you can use Windows API calls, this code works on Win XP, and probably Win 2000 as well. I don't know about Vista.
Code: Select all
; set registry keys for center/tile/stretch
If RegOpenKeyEx_(#HKEY_CURRENT_USER, "Control Panel\\Desktop\\", 0, #KEY_ALL_ACCESS, @key.l) = #ERROR_SUCCESS
Select WPType
Case "c" ; center
TileWP.s = "0"
WPStyle.s = "1"
Case "t" ; tile
TileWP.s = "1"
WPStyle.s = "0"
Case "s" ; stretch
TileWP.s = "0"
WPStyle.s = "2"
EndSelect
RegSetValueEx_(key, "TileWallpaper", 0, #REG_SZ, TileWP, 2)
RegSetValueEx_(key, "WallpaperStyle", 0, #REG_SZ, WPStyle, 2)
EndIf
Regards,
Eric
Posted: Thu Sep 20, 2007 2:51 pm
by Kaeru Gaman
thnx Eric

Posted: Thu Sep 20, 2007 3:47 pm
by Sparkie
@ebs: Thank you

@Kaeru Gaman: Sorry I was late
@ricardo: See if this works any better for you...
Code: Select all
;...Wallpaper changer by Sparkie
#WPSTYLE_CENTER = 0
#WPSTYLE_TILE = 1
#WPSTYLE_STRETCH = 2
#WPSTYLE_MAX = 3
#AD_APPLY_SAVE = 1
#AD_APPLY_HTMLGEN = 2
#AD_APPLY_REFRESH = 4
#AD_APPLY_FORCE = 8
#AD_APPLY_BUFFERED_REFRESH = 10
#AD_APPLY_COMPLETEREFRESH = 20
#AD_APPLY_DYNAMICREFRESH = 20
#AD_APPLY_ALL = #AD_APPLY_SAVE | #AD_APPLY_HTMLGEN | #AD_APPLY_REFRESH
Structure myWALLPAPEROPT
dwSize.l
dwStyle.l
EndStructure
Global wallpaperOptions.myWALLPAPEROPT
Global deskObj.IActiveDesktop
CoInitialize_(0)
If CoCreateInstance_(?CLSID_ActiveDesktop,0,1,?IID_IActiveDesktop,@deskObj.IActiveDesktop) <> #S_OK
MessageRequester("Error", "Could not create object")
Quit = #True
EndIf
Procedure doWallpaper(myWallpaper$)
wallpaperOptions\dwSize = SizeOf(myWALLPAPEROPT)
;... get option selection
If GetGadgetState(2)
wallpaperOptions\dwStyle = #WPSTYLE_TILE
ElseIf GetGadgetState(3)
wallpaperOptions\dwStyle = #WPSTYLE_STRETCH
Else
wallpaperOptions\dwStyle = #WPSTYLE_CENTER
EndIf
;... allocate for wStr filename
*filenameWide = AllocateMemory(Len(myWallpaper$)*2+2)
PokeS(*filenameWide, myWallpaper$, -1, #PB_Unicode)
If deskObj\SetWallpaperOptions(@wallpaperOptions, 0) = #S_OK
If deskObj\SetWallpaper(*filenameWide, 0) = #S_OK
If deskObj\ApplyChanges(#AD_APPLY_ALL) <> #S_OK
MessageRequester("Error", "Unable to apply changes to Wallpaper.")
EndIf
EndIf
EndIf
FreeMemory(*filenameWide)
ProcedureReturn 0
EndProcedure
If OpenWindow(0, 10, 10, 200, 150, "Change Wallpaper", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) And CreateGadgetList(WindowID(0))
ButtonGadget(1, 50, 10, 100, 40, "Select Wallpaper")
OptionGadget(2, 60, 60, 100, 20, "Tile")
OptionGadget(3, 60, 90, 100, 20, "Stretch")
OptionGadget(4, 60, 120, 100, 20, "Center")
SetGadgetState(3,1)
Repeat
event = WaitWindowEvent()
Select event
Case #PB_Event_Gadget
Select EventGadget()
Case 1
wallpaper$ = Space(#MAX_PATH)
wallpaper$ = OpenFileRequester("Select Wallpaper", "c:\", "*.bmp *.jpg *.jpeg | *.bmp;*.jpg", 0 )
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 2
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 3
If wallpaper$
doWallpaper(wallpaper$)
EndIf
Case 4
If wallpaper$
doWallpaper(wallpaper$)
EndIf
EndSelect
Case #PB_Event_CloseWindow
Quit = #True
EndSelect
Until Quit = #True
If deskObj
deskObj\Release()
EndIf
CoUninitialize_()
EndIf
End
DataSection
CLSID_ActiveDesktop:
Data.l $75048700
Data.w $EF1F,$11D0
Data.b $98,$88,$00,$60,$97,$DE,$AC,$F9
IID_IActiveDesktop:
Data.l $F490EB00
Data.w $1240,$11D1
Data.b $98,$88,$00,$60,$97,$DE,$AC,$F9
EndDataSection
Posted: Thu Sep 20, 2007 10:18 pm
by ricardo
Excellent Sparkie!!
Thanks

Posted: Fri Sep 21, 2007 3:01 am
by Sparkie
You're welcome

Posted: Fri Sep 21, 2007 10:05 am
by Kaeru Gaman
Sparkie wrote:@Kaeru Gaman: Sorry I was late
no problem...
additional question:
is there a way to
- change wallpaper via registry
- change tilings via SystemParametersInfo_
?
Gregs Attempt to change wallpaper uses SystemParametersInfo_,
Erics solution for tiling uses registry entries.
is it possible to do both the same way?
Posted: Fri Sep 21, 2007 1:18 pm
by Sparkie
SystemParametersInfo_ () should work if you select a BMP rather than a JPG image. You can then use the Registry to set the style as desired.
Kaeru Gaman wrote:...and I will not try a Code that may change my Desktop to "Active".
I completely understand your point of view on Active Desktop. I can't guarantee you the same success as me, but I do NOT have Active Desktop enabled on my XP system and my code above works just fine with no problems.
