VB6: Modifying the image of the desktop

Last update on August 23, 2009 11:17 AM by jak58
Published by netty5

VB6: Modifying the image of the desktop + write changes to the registry






As stated here is a short tip, allowing you to change the image of the desktop, including the modifications in the registry.

Project initialization


Open a new project
In the Form paste the following piece of information:

'1 textBox Name = Text1
'1 CommandButton  Name = Apply					
                ' caption = Apply
'3 x OptionButton Name = Option1
'   index = 0 : caption = Center
'   index = 1 : caption = Mosaique
'   index = 2 : caption = Stretch


A CommondDialog can be added, to search for image file. (Note that in this case it is not necessary)

Testing


For testing purposes, put the full path and name of an image file in text1

In the module of the Form

Option Explicit

Private Declare Function SystemParametersInfo Lib "User32" Alias "SystemParametersInfoA" _
(ByVal uAction As Long, ByVal uParam As Long, ByVal lpvParam As String, ByVal fuWinIni As Long) As Long

 Const SPI_SETDESKWALLPAPER = 20
 Const SPIF_UPDATEINIFILE = &H1
 Const SPIF_SENDWININICHANGE = &H2


' API for Registry:
' ---------------------------------------------
 Private Declare Function RegCloseKey Lib "advapi32.dll" (ByVal Hkey As Long) As Long
 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

 Const HKEY_CURRENT_USER = &H80000001
 Const ERROR_SUCCESS = 0&
 Const REG_SZ = 1
 
 Dim FileName As String
 Dim AffiType As Integer

Private Sub Apply_Click()
Dim Txt1 As String, Txt2 As String
Dim R As Long
Dim Hand As Long
    'Manage error if no image found
    On Error Resume Next

    FileName = Text1.Text

' Put options in the registry
    Select Case AffiType
    Case 0 ' Center
        Txt1 = "0": Txt2 = "0"
    Case 1 ' Mosaïc
        Txt1 = "0": Txt2 = "1"
    Case 2 ' Stretch
        Txt1 = "2": Txt2 = "0"
    End Select
   R = RegCreateKey(HKEY_CURRENT_USER, "Control Panel\Desktop", Hand)
   R = RegSetValueEx(Hand, "WallpaperStyle", 0, REG_SZ, ByVal Txt1, Len(Txt1))
   R = RegCloseKey(Hand)
   
   R = RegCreateKey(HKEY_CURRENT_USER, "Control Panel\Desktop", Hand)
   R = RegSetValueEx(Hand, "TileWallpaper", 0, REG_SZ, ByVal Txt2, Len(Txt2))
   R = RegCloseKey(Hand)
   
    SystemParametersInfo SPI_SETDESKWALLPAPER, 0&, FileName, SPIF_UPDATEINIFILE Or _
    SPIF_SENDWININICHANGE

End Sub

Private Sub Option1_Click(Index As Integer)
    AffiType = Index

End Sub
Best answers for « VB6: Modifying the image of the desktop » in :
Download Google Desktop Show It is so easy and better to surf the interface of Google, that they would like to use it on our office as research motor. Google Desktop is the office software version of Google. He allows to perform researches on your computer as he makes it on...
Changing your desktop background! Show Changing your desktop background! Desktop background is the image or wallpaper that is being used as background on a computer screen. Wallpaper is the common terms used for designating the graphical interface in Microsoft Windows. Below...
[Gnome] Changing the desktop background Show [Gnome] Changing the desktop background From the context menu of the image Drag and drop on the desktop Quickly change the desktop background To change the wallpaper under Nautilus, you must open the image viewer, then select...
Converting your PDF file into an Image ShowConverting your PDF file into an Image Universal Document Converter PDF2IMAGE PDF TO IMAGE CONVERTER You could have encountered difficulties to modify PDF docs in the past. Nowadays this is no more trouble as there are several PDF...
Free aquarium Desktop Wallpapers ShowFree aquarium Desktop wallpapers Find the best Resolutions for your Desktop wallpaper Download a wallpaper through GOOGLE images There are a lot of websites where you can download free aquarium screen savers, marines species, animated...
[Word] Background image Show[WORD] Background image It is possible in Microsoft Word to display a background image in a document by clicking on the Format menu, then click Background and then click Grounds and textures. In the Picture tab, click "Select...
Download R-Drive Image ShowR-Drive Image creates disk image files for backup or for your CD / DVD. The image files can then be stored in the various removable media. The program is capable of restoring images on removable media or hard disk. Advantage R-Drive Image creates...
Download Free Word/Doc Txt to Image Jpg/Jpeg Bmp Tiff Png ShowIt is usually the images that we insert into Word, Excel or PowerPoint documents. This time, it is the opposite, because we are going to convert these documents to image formats. All to Jpg / JPEG Image Bmp Tiff Png Converter is a powerful tool which...
Managing images in HTML ShowHow do you display images on a web page? Having a few images on a website can make it more attractive and user-friendly. However, it is important not to go overboard, since images can take a long time to load, and in some cases can make a document...