PDA

Click to See Complete Forum and Search --> : WallPaper


Candiabreu
Feb 21st, 2001, 01:27 PM
How can I set the windows wallpaper to my picture by VB code?

THANK YOU!

Feb 21st, 2001, 01:50 PM
Try this:


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

Candiabreu
Feb 21st, 2001, 01:55 PM
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!

Feb 21st, 2001, 04:03 PM
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

YoungBuck
Feb 21st, 2001, 04:13 PM
Hey Matthew when you are writing to the Win.ini file you can just use the WriteProfileString function....



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

Candiabreu
Feb 22nd, 2001, 06:30 AM
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

Kevin Seiden
Feb 23rd, 2001, 11:49 PM
Visit Here, download the demo... it works.
http://www.vb-world.net/demos/wallpaper/

pramod kumar
Feb 24th, 2001, 08:04 PM
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)