How can I set the windows wallpaper to my picture by VB code?
THANK YOU!
Printable View
How can I set the windows wallpaper to my picture by VB code?
THANK YOU!
Try this:
Code:Private Declare Function GetPrivateProfileString _
Lib "kernel32" Alias "GetPrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As String, _
ByVal lpDefault As String, ByVal lpReturnedString As _
String, ByVal nSize As Long, ByVal lpFileName As String) As _
Long
Private Function ReadINI(strsection As String, strkey As String, strfullpath As String) As String
Dim strbuffer As String
Let strbuffer$ = String$(750, Chr$(0&))
Let ReadINI$ = Left$(strbuffer$, GetPrivateProfileString(strsection$, ByVal LCase$(strkey$), "", strbuffer, Len(strbuffer), strfullpath$))
End Function
Private Sub Form_Load()
Picture1.Picture = LoadPicture(ReadINI("Desktop", "Wallpaper", "C:\Windows\Win.INI"))
End Sub
I'm sorry, Matthew.
In reality I want to set my picture to the windows wallpaper.
I want to change the windows wallpaper, by VB code.
Thank you!
Code:Private Declare Function WritePrivateProfileString _
Lib "kernel32" Alias "WritePrivateProfileStringA" (ByVal _
lpApplicationName As String, ByVal lpKeyName As Any, ByVal _
lpString As Any, ByVal lpFileName As String) As Long
Private Sub WriteINI(strsection As String, strkey As String, strkeyvalue As String, strfullpath As String)
Call WritePrivateProfileString(strsection$, UCase$(strkey$), strkeyvalue$, strfullpath$)
End Sub
Private Sub Form_Load()
Call WriteINI("Desktop", "Wallpaper", "C:\MyPic.bmp", "C:\Windows\Win.INI")
End Sub
Hey Matthew when you are writing to the Win.ini file you can just use the WriteProfileString function....
Code:
Option Explicit
Private Declare Function WriteProfileString Lib "kernel32" Alias "WriteProfileStringA" (ByVal lpszSection As String, ByVal lpszKeyName As String, ByVal lpszString As String) As Long
Private Sub WriteWinINI(strsection As String, strkey As String, strkeyvalue As String)
Call WriteProfileString(strsection$, UCase$(strkey$), strkeyvalue$)
End Sub
Private Sub Form_Load()
Call WriteWinINI("Desktop", "Wallpaper", "C:\Windows\Forest.bmp")
End Sub
Thank you, guys, by your attention. But it doesn't work.
I changed the win.ini file (by your code) but it doesn't changed the Register (in Register Editor).
I think that is missing something.
[]'s
Visit Here, download the demo... it works.
http://www.vb-world.net/demos/wallpaper/
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
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1
Const SPIF_SENDWININICHANGE = &H2
dim a as Long,strFileName as String
strFileName="c:\windows\desktop\a.bmp"
a = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strFileName, SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)