5thcav
asked on
API call ; I need to get the currentwallpaper ; This code may help
sorry i dont remembe where i got this code,,, but it dosnt work anyway (grin)
but im looking to get the currentwallpaper section to work, TIA
Description:
Three functions, LoadWallpaper, ResetWallpaper, and CurrentWallpaper do what their name implies.
Code:
Option Explicit
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = &H1
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1
Private 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
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, _
lpcbData As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey _
As Long) As Long
Public Sub LoadWallpaper(sFilename As String)
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, sFilename, _
SPIF_UPDATEINIFILE
End Sub
Public Sub ResetWallpaper()
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, CurrentWallpaper, 0
End Sub
Public Function CurrentWallpaper() As String
Dim sValue As String
Dim nReturn As Long
Dim hKey As Long
RegOpenKeyEx HKEY_CURRENT_USER, "Control panel\desktop", 0, 0, hKey
nReturn = 1024
sValue = Space(1024)
RegQueryValueEx hKey, "Wallpaper", 0, REG_SZ, sValue, nReturn
sValue = Mid(sValue, 1, nReturn)
RegCloseKey hKey
CurrentWallpaper = sValue
End Function
Sample Usage:
LoadWallpaper "c:\windows\clouds.bmp"
but im looking to get the currentwallpaper section to work, TIA
Description:
Three functions, LoadWallpaper, ResetWallpaper, and CurrentWallpaper do what their name implies.
Code:
Option Explicit
Private Const SPI_SETDESKWALLPAPER = 20
Private Const SPIF_UPDATEINIFILE = &H1
Private Const HKEY_CURRENT_USER = &H80000001
Private Const REG_SZ = 1
Private 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
Private Declare Function RegQueryValueEx Lib "advapi32.dll" Alias _
"RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, _
ByVal lpReserved As Long, lpType As Long, ByVal lpData As String, _
lpcbData As Long) As Long
Private Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias _
"RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, _
ByVal ulOptions As Long, ByVal samDesired As Long, _
phkResult As Long) As Long
Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey _
As Long) As Long
Public Sub LoadWallpaper(sFilename As String)
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, sFilename, _
SPIF_UPDATEINIFILE
End Sub
Public Sub ResetWallpaper()
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, CurrentWallpaper, 0
End Sub
Public Function CurrentWallpaper() As String
Dim sValue As String
Dim nReturn As Long
Dim hKey As Long
RegOpenKeyEx HKEY_CURRENT_USER, "Control panel\desktop", 0, 0, hKey
nReturn = 1024
sValue = Space(1024)
RegQueryValueEx hKey, "Wallpaper", 0, REG_SZ, sValue, nReturn
sValue = Mid(sValue, 1, nReturn)
RegCloseKey hKey
CurrentWallpaper = sValue
End Function
Sample Usage:
LoadWallpaper "c:\windows\clouds.bmp"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks
ASKER