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"
I searched and found these resources guiding about this API, you may also google "vb.net set desktop wallpaper".
<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
API Call Authentic Sources:
- http://msdn.microsoft.com/en-us/library/ms724947(VS.85).aspx (search vb.net on this page to get it)
DetailsIn 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".
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.
pvParamThis contains the complete filepath of our wallpaper / image file that we are to set as desktop wallpaper
fWinIniUpdates 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.