Results 1 to 8 of 8

Thread: WallPaper

  1. #1

    Thread Starter
    New Member Candiabreu's Avatar
    Join Date
    Feb 2001
    Location
    Brasil
    Posts
    13

    Thumbs up

    How can I set the windows wallpaper to my picture by VB code?

    THANK YOU!

  2. #2
    Guest
    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

  3. #3

    Thread Starter
    New Member Candiabreu's Avatar
    Join Date
    Feb 2001
    Location
    Brasil
    Posts
    13
    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!

  4. #4
    Guest
    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

  5. #5
    Fanatic Member
    Join Date
    Sep 1999
    Location
    Bethel, North Carolina, USA
    Posts
    987
    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
    {Insert random techno-babble here}

    {Insert quote from some long gone mofo here}

  6. #6

    Thread Starter
    New Member Candiabreu's Avatar
    Join Date
    Feb 2001
    Location
    Brasil
    Posts
    13
    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

  7. #7

    Wink

    Visit Here, download the demo... it works.
    http://www.vb-world.net/demos/wallpaper/

  8. #8
    Member
    Join Date
    Feb 2001
    Location
    Kerala, India
    Posts
    42

    Talking Try this code

    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)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width