VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Correctly setting Desktop Wallpaper

by Steven Henning (1 Submission)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Unknown Difficulty
Date Added: Wed 3rd February 2021
Rating: (39 Votes)

I got tired of trying every wallpaper example on this site and finding they didn't work
on Windows NT.
This shows the example from Microsoft of how to correctly set the Desktop Wallpaper
from Visual Basic.
Original code is from :-
https://msdn.microsoft.com/library/techart/msdn_msdn192.htm
Seeing
we are not allowed to link to another site, I just copied the code from
the above URL and modified it slightly.

Assumes
Add a Command Button control to Form1. Command1 is created by default. Set its Caption property to "Remove Wallpaper". Add a second Command Button control to Form1. Command2 is created by default. Set its Caption property to "Change Wallpaper".
API Declarations
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

Rate Correctly setting Desktop Wallpaper

Private Sub Command1_Click()
  Dim X As Long
  X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, "(None)", _
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
  MsgBox "Wallpaper was removed"
End Sub
Private Sub Command2_Click()
  Dim FileName As String
  Dim X As Long
  ' Windows NT
  FileName = "c:\winnt\Coffee Bean.bmp"
  ' Windows 95 users, uncomment this line, you can delete the previous line
'  FileName = "c:\windows\Coffee Bean.bmp"

  X = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0&, FileName, _ 
SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE)
  MsgBox "Wallpaper was changed"
End Sub

Download this snippet    Add to My Saved Code

Correctly setting Desktop Wallpaper Comments

No comments have been posted about Correctly setting Desktop Wallpaper. Why not be the first to post a comment about Correctly setting Desktop Wallpaper.

Post your comment

Subject:
Message:
0/1000 characters