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 :
VB6: Modifying the image of the desktop Show VB6: Modifying the image of the desktop + write changes to the registry Project initialization Testing As stated here is a short tip, allowing you to change the image of the desktop, including the modifications in the...
Restrict change of background Show Restrict change of background This tips has been raised out to show you how to configure and restrict the background change of your computer for specific purpose like company policy. Go to menu Start and select Run Then type...
Free aquarium Desktop Wallpapers Show Free 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...
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...
Changing your desktop background! ShowChanging 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...
[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 LBE Desktop helpdesk ShowIn order to improve your customer service, LBE Desktop Helpdesk is a help tool which is very easy to use. Compatible with database MS Access, SQL Server or Oracle, it allows you to control your data presentation: their organization,...
Download Google Desktop ShowIt 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...
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...
Vector and bitmap images Showvector images and bitmap images There are two main categories of images: bitmap images (also called raster images): these are pixeled images, i.e. a set of points (pixels) contained in a table, each of these points having one or more values...