Results 1 to 4 of 4

Thread: Setting a wallpaper to tile or center or strech

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    12
    I pasted the following code together from misc. bits of code all over the net. I want to add in the function so that there are three radio buttons, one set to center, one set to tile, and one set to strech the wallpaper. Any ideas?
    Thanks
    Adrift

    ---Code Pasted---
    Private Const RDW_INVALIDATE = &H1
    Private Const RDW_INTERNALPAINT = &H2
    Private Const RDW_ERASE = &H4
    Private Const RDW_VALIDATE = &H8
    Private Const RDW_NOINTERNALPAINT = &H10
    Private Const RDW_NOERASE = &H20
    Private Const RDW_NOCHILDREN = &H40
    Private Const RDW_ALLCHILDREN = &H80
    Private Const RDW_UPDATENOW = &H100
    Private Const RDW_ERASENOW = &H200
    Private Const RDW_FRAME = &H400
    Private Const RDW_NOFRAME = &H800

    Private Type RECT
    Left As Long
    Top As Long
    Right As Long
    Bottom As Long
    End Type

    Private Declare Function CreateRectRgnIndirect Lib "gdi32" _
    (lpRect As RECT) As Long

    Private Declare Function RedrawWindow Lib "user32" _
    (ByVal hwnd As Long, lprcUpdate As RECT, ByVal hrgnUpdate _
    As Long, ByVal fuRedraw As Long) As Long


    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

    Private Sub cmdChangeWallpaper_Click()
    SystemParametersInfo SPI_SETDESKWALLPAPER, 0, (Picpath & List1.Text), SPIF_UPDATEINIFILE

    Dim udtScrDim As RECT
    Dim lReturn As Long
    Dim hRegion As Long

    udtScrDim.Left = 0
    udtScrDim.Top = 0
    udtScrDim.Right = Screen.Width
    udtScrDim.Bottom = Screen.Height
    hRegion = CreateRectRgnIndirect(udtScrDim)

    If hRegion <> 0 Then
    lReturn = RedrawWindow(0, udtScrDim, hRegion, _
    RDW_ERASE Or RDW_FRAME Or RDW_INVALIDATE Or RDW_UPDATENOW Or RDW_INTERNALPAINT Or RDW_ALLCHILDREN)
    End If

    End Sub

  2. #2
    Fanatic Member
    Join Date
    Jan 2000
    Location
    Nitro
    Posts
    633

    You can do it like this.

    Code:
    Option Explicit
    
    Private Declare Function RegCreateKey Lib "advapi32.dll" Alias "RegCreateKeyA" (ByVal hKey As Long, ByVal lpSubKey As String, phkResult As Long) As Long
    Private 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
    Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
    
    Private Const HKEY_CURRENT_USER = &H80000001
    Private Const REG_SZ = 1
    
    'Reboot after running this procedure for the effect to take place!
    Sub Main()
      Dim str_KeyFolder As String
      'NOTICE:There are two type of wallpaper.
      
    '  'PURPOSE: Wallpaper1 - The bitmap wallpaper when the computer is lock
    '  '         HKEY_CURRENT_USER\Control Panel\Desktop
    '  '         Drop the prefix "HKEY_CURRENT_USER\"
    '  str_KeyFolder = "Control Panel\Desktop"
      
      'PURPOSE: Wallpaper2 - The jpeg/bitmap wallpaper of the desk top
      '         HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General
      '         Drop the prefix "HKEY_CURRENT_USER\"
      str_KeyFolder = "Software\Microsoft\Internet Explorer\Desktop\General"
      
      'PURPOSE: This will change the wallpaper.
      Call p_ChangeWallPapper(str_KeyFolder, "Wallpaper", "C:\Blue.jpg")
    
      'PURPOSE: This will set the wallpaper style of the wallpaper to Stretch.
      '"1" = Tile
      '"0" = Centered
      '"2" = Stretch (Win98)
      Call p_ChangeWallPapper(str_KeyFolder, "WallpaperStyle", "2")
    End Sub
    
    Sub p_ChangeWallPapper(str_KeyFolder As String, str_Field As String, str_File As String)
        Dim lng_Key As Long
        
        'PURPOSE: The RegCreateKey function creates the specified registry key.
        '         If the key already exists in the registry, the function opens it.
        If Not RegCreateKey(HKEY_CURRENT_USER, str_KeyFolder, lng_Key) = 0 Then Exit Sub
        
        'PURPOSE: The RegSetValueEx function sets the data and
        '         type of a specified value under a registry key.
        Call RegSetValueEx(lng_Key, str_Field, 0, REG_SZ, ByVal str_File, Len(str_File))
        
        'PURPOSE: The RegCloseKey function releases a handle to the specified registry key.
        Call RegCloseKey(lng_Key)
    End Sub
    Chemically Formulated As:
    Dr. Nitro

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2000
    Posts
    12

    I still need instant change of wallpaper

    Thanks for the suggestion but I need the wallpaper to be instantly updated - Any other ideas?

  4. #4
    Junior Member
    Join Date
    Feb 2003
    Location
    Sweden
    Posts
    27
    To have it update direct use both methods. First change the registry settings and then use

    Code:
    SystemParametersInfo SPI_SETDESKWALLPAPER, 0, (Picpath & List1.Text), SPIF_UPDATEINIFILE
    It works in my program when tested on winXP anyway.

    'henrik

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