In the registry, not in the INI files.
Actually, the Wallpaper= thing in the INI Files is just there for compatibility with old programs. The wallpaper location is loaded from the registry:
HKEY_CURRENT_USER\Control Panel\Desktop\Wallpaper
This is set to the filename of the BMP thingie where your coolio wallpaper is.
Almost every Monday there is also a neato thing there:
HKEY_CURRENT_USER\Control Panel\Desktop\WallpaperStyle
This can be "0" - Center or "1" - Tile. (Windows 98: "2" - Stretch)
And finally, here is how to set these things:
(This code really loves living in modules! So put it in a module and it will work happily!)
Code:
Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
Declare Function RegSetValueEx Lib "advapi32.dll" Alias "RegSetValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal Reserved As Long, ByVal dwType As Long, lpData As Any, ByVal cbData As Long) As Long
Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_CURRENT_USER = &H80000001
Public Const REG_SZ = 1
Sub ChangeWallpaperThingie(ByVal sWhatToChange As String, ByVal sNewValue As String)
Dim hKey As Long
If Not RegCreateKey(HKEY_CURRENT_USER, "\Control Panel\Desktop", hKey) = 0 Then Exit Sub
Call RegSetValueEx(hKey, sWhatToChange, 0, REG_SZ, ByVal sNewValue, Len(sNewValue))
Call RegCloseKey(hKey)
End Sub
This should be enough to alter your registry. I would say don't try this at home but how would you get it to work otherwise? What I'm saying is, don't mess with the registry unless you know what you're doing or if you got the code from someone who told you to not mess with the registry unless you know what you're doing.
This is how you use the code carefully without any crashes or anything weird hopefully:
Call ChangeWallpaperThingie("Wallpaper", "C:\Windows\Clouds.bmp")
This will set the wallpaper to Clouds.bmp.
Call ChangeWallpaperThingie("WallpaperStyle", "1")
This will set the wallpaper style to Tiled.
Instead of "1", use "0" for Centered or "2" (Windows 98 and maybe other nifty versions of the somewhat-horrible OS) Stretch.
To make the wallpaper and wallpaper style take effect, you must convince the user to restart. Or do it yourself:
(Remember how my code loves modules!)
Code:
Declare Function ExitWindowsEx Lib "user32" Alias "ExitWindowsEx" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Public Const EWX_REBOOT = 2
Sub RebootWindows()
Call ExitWindowsEx(EWX_REBOOT, 0)
End Sub
Call RebootWindows
This will do the job.
P.S.
About the whole "WallpaperStyle" thing... Maybe, I don't know anymore, nothing there works on versions earlier than 98. If that is the case, instead of "WallpaperStyle use "TileWallpaper" and make it "0" for Center or "1" for Tile.
re: just to complicate matters
Just to complicate matters how do i update the "active desktop" so i can display internet pictures(.jpg, .gif), instead of .bmp? I'm making a wallpaper changer and .bmp files works fine.
This will change your wall paper imediately!
Here is a faster way to set the wall paper.
Code:
Option Explicit
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97
Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPIF_SENDWININICHANGE = &H2
Public Const SPIF_UPDATEINIFILE = &H1
Sub p_WallPaper()
' PURPOSE: Send the current picture to the clipboard
Clipboard.SetData LoadPicture("C:\Whatever.bmp"), vbCFBitmap
DoEvents
' PURPOSE: Save the clipboard picture
SavePicture Clipboard.GetData(vbCFBitmap), "C:\Test.bmp"
' PURPOSE:Change the wallpaper
Call SystemParametersInfo(SPI_SETDESKWALLPAPER, True, "C:\Test.bmp", SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub
If you want to load a jpg, load it into a image control and do a Savepicture.
Here are my original codes!
Code:
Option Explicit
Public Declare Function SystemParametersInfo Lib "user32" Alias "SystemParametersInfoA" (ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As Any, ByVal fuWinIni As Long) As Long
Public Const SPI_SCREENSAVERRUNNING = 97
Public Const SPI_SETDESKWALLPAPER = 20
Public Const SPIF_SENDWININICHANGE = &H2
Public Const SPIF_UPDATEINIFILE = &H1
Public Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Sub p_WallPaper()
' PURPOSE: Send the current picture to the clipboard
Clipboard.SetData LoadPicture(frmMain_Directory.File1.List(frmView.imgStretch.Tag)), vbCFBitmap
' PURPOSE: Send the Entire Screen to the clipboard
'Call keybd_event(vbKeySnapshot, 1, 0, 0)
' PURPOSE: Send the Active Window to the clipboard
'Call keybd_event(vbKeySnapshot, 0, 0, 0)
DoEvents
' PURPOSE: Save the clipboard picture
SavePicture Clipboard.GetData(vbCFBitmap), "C:\Test.bmp"
' PURPOSE:Change the wallpaper
Call SystemParametersInfo(SPI_SETDESKWALLPAPER, True, "C:\Test.bmp", SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
End Sub