-->

VB.Net 2008 - Change Desktop Wallpaper from code

maqk® by Unknown | 2:46 AM

Initially, some fun - So the history behind this micro utility is, I bought Dell 15 Studio, Vista eXperience, DreamScene made me more deskTopCrazy, saw Windows 7's random wallpaper changer, searched one for Vista, downloaded apps didn't work , hence decided to make one.

NOTE: The scope of this blogpost is limited to the main API Call that sets a new Wallpaper. The whole utility, its code and details will be posted later in another blogpost. So fingers crossed.

Now for work, its a simple user32.dll API Call to the method, "SystemParametersInfo"

<dllimport("user32.dll", )="" entrypoint:="SystemParametersInfo">_

Public Shared Function SystemParametersInfo(ByVal uiAction As UInteger, ByVal uiParam As UInteger, ByVal pvParam As String, ByVal fWinIni As UInteger) As Boolean



End Function
I searched and found these resources guiding about this API, you may also google "vb.net set desktop wallpaper".

API Call Authentic Sources:
The 2nd link is a more accurate call to the API since this systax worked for me in Vb.net 2008

Details

In the API, the entry point for us is the method, SystemParametersInfo. This function is responsible for so many things, including setting wallpaper for us. A description from msdn is quoted as;
"Retrieves or sets the value of one of the system-wide parameters. This function can also update the user profile while setting a parameter". 

Parameters

This function takes 4 arguments, first one, the most important one is about the work this function is gonna do for ur, so we pass an integer constant, 'SPI_SETDESKWALLPAPER' containing a value of 20.

uParam:

If you google it, most probably the first descriiption you will get is;
"A parameter whose usage and format depends on the system parameter being queried or set. For more information about system-wide parameters, see the uiAction parameter. If not otherwise indicated, you must specify zero for this parameter."

I googled more and found that uParam is set 0 with GET Constant and with SET, the new value should be sent, however in my app, I used 0 and 1 and found a same result with no exceptions. If some one finds a more detailed exlanation, please provide me too. The explanation about these parameters are also limited because the subject function deals with lots of functionality, hence these variables depend on the context of use.

pvParam

This contains the complete filepath of our wallpaper / image file that we are to set as desktop wallpaper

fWinIni

Updates the Win.ini file. The source i used as  alead used 2 constants,

Private Const SPIF_UPDATEINIFILE = 1
Private Const SPIF_SENDWININICHANGE = 2


And the argument was passed as follows;
SystemParametersInfo(SPI_SETDESKWALLPAPER, 1, _WallPaperPath, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)

see the italic text, they ised or in between the 2 variables. However in my testing, I used each of them individually and found no difference.

Sources:
I will return with my whole Rando Wallpaper changer in the next blog, till them, some additional functionality to be implemented to make it a complete product. See you then,

MAQK.
top