Change Desktop Wallpaper

how can we change desktop wallpaper in VB6.0 using source codes

Page 1 of 1

4 Replies - 11274 Views - Last Post: 09 June 2009 - 01:15 AM Rate Topic: -----

#1 ryden_ryge  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 06-January 09

Change Desktop Wallpaper

Posted 06 January 2009 - 01:57 AM

How can we change the desktop wallpaper in Visual Basic 6.0.

** Edit ** Removed unused blocks
Is This A Good Question/Topic? 0
  • +

Replies To: Change Desktop Wallpaper

#2 Jayman  Icon User is offline

  • Student of Life
  • member icon

Reputation: 418
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: Change Desktop Wallpaper

Posted 06 January 2009 - 10:18 AM

What have you tried so far?

[rules][/rules]
Was This Post Helpful? 0
  • +
  • -

#3 vinod1972  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 09-June 09

Re: Change Desktop Wallpaper

Posted 09 June 2009 - 12:55 AM

'the program in vb is given below/also received from net

Option Explicit

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

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


Public Enum REG_TOPLEVEL_KEYS
 HKEY_CLASSES_ROOT = &H80000000
 HKEY_CURRENT_CONFIG = &H80000005
 HKEY_CURRENT_USER = &H80000001
 HKEY_DYN_DATA = &H80000006
 HKEY_LOCAL_MACHINE = &H80000002
 HKEY_PERFORMANCE_DATA = &H80000004
 HKEY_USERS = &H80000003
End Enum


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 RegCloseKey Lib _
   "advapi32.dll" (ByVal Hkey 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 Const REG_SZ = 1


Public Function ChangeWallPaper(ImageFile As String, Tile As Boolean)

'Pass Full Path of .BMP to this function
'Returns true if successful, false otherwise
'If you want to tile, set Tile to True

Dim lRet As Long
On Error Resume Next

If Tile Then WriteStringToRegistry HKEY_CURRENT_USER, _
  "Control Panel\desktop", "TileWallpaper", "1"
  
lRet = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, ImageFile, _
   SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
ChangeWallPaper = lRet <> 0 And Err.LastDllError = 0
End Function

Private Function WriteStringToRegistry(Hkey As _
  REG_TOPLEVEL_KEYS, strPath As String, strValue As String, _
  strdata As String) As Boolean
 

Dim bAns As Boolean

On Error GoTo ErrorHandler
   Dim keyhand As Long
   Dim r As Long
   r = RegCreateKey(Hkey, strPath, keyhand)
   If r = 0 Then
		r = RegSetValueEx(keyhand, strValue, 0, _
		   REG_SZ, ByVal strdata, Len(strdata))
		r = RegCloseKey(keyhand)
	End If
	
   WriteStringToRegistry = (r = 0)

Exit Function

ErrorHandler:
	WriteStringToRegistry = False
	Exit Function
	
End Function




Private Sub Form_Load()
Dim x, sourcef
sourcef = "c:\Yourimage.bmp" 'give the full path of image file that you want to put on desktop
x = ChangeWallPaper(sourcef, False)
Unload Me
End Sub



** Edit ** :code:
Was This Post Helpful? 0
  • +
  • -

#4 firebolt  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 92
  • View blog
  • Posts: 5,561
  • Joined: 20-February 09

Re: Change Desktop Wallpaper

Posted 09 June 2009 - 01:00 AM

Please start a new thread, rather than raiding another. It will gain better help.



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 
Public Const SPI_SETDESKWALLPAPER = 20

Dim lngResult As Long
Dim strBmp As String

strBmp = "c:\yourimage.bmp"
lngResult = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, strBitmapImage, 0)



Was This Post Helpful? 0
  • +
  • -

#5 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5388
  • View blog
  • Posts: 27,384
  • Joined: 10-May 07

Re: Change Desktop Wallpaper

Posted 09 June 2009 - 01:15 AM

@vinod1972

You're obviously eager to help out, however we ask that when someone asks for code they at least show good faith that they made an attempt to solve the problem. We want to avoid people having their projects or homework simply done for them with no effort on their part.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1