Valhalla Legends Archive

Programming => General Programming => Topic started by: iago on October 07, 2003, 12:09 AM

Title: Desktop Wallpaper
Post by: iago on October 07, 2003, 12:09 AM
Is there an API call or something like that to change the desktop wallpaper in Windows (2k or xp or whatever)?  

I want to make a program that will change wallpaper based on holidays/time of year.  Yes, I'm that bored.

If somebody knows of a program that does that anyway without me having to write it, that's ok too :-)
Title: Re:Desktop Wallpaper
Post by: iago on October 07, 2003, 12:10 AM
hm, this looks like a promising place to start:

http://www.pscode.com/vb/scripts/ShowCode.asp?txtCodeId=304&lngWId=3
Title: Re:Desktop Wallpaper
Post by: iago on October 07, 2003, 12:24 AM
hmm, it seems to be stored in the registry under:
"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper"

Now all I have to figure out is how to tell windows to reload the wallpaper :-)

Edit: hmm, I can just close/open explorer.exe, which works.. or I can do this before explorer loads initially.  How early do startup programs run, before or after explorer?

Title: Re:Desktop Wallpaper
Post by: Eibro on October 07, 2003, 07:06 AM
Quote from: iago on October 07, 2003, 12:24 AM
hmm, it seems to be stored in the registry under:
"HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\General\Wallpaper"

Now all I have to figure out is how to tell windows to reload the wallpaper :-)

Edit: hmm, I can just close/open explorer.exe, which works.. or I can do this before explorer loads initially.  How early do startup programs run, before or after explorer?


You could probably just invalidate the entire desktop and force windows to repaint it.
Title: Re:Desktop Wallpaper
Post by: Grok on October 07, 2003, 07:21 AM
   Dim Files() As String, FN As String
   Dim lCnt As Long, bRet As Long
   Static Current As Long
   Dim nAction As Long, nSaveChange As Long
   Dim strPic As String
   
   lCnt = 0
   FN = Dir("C:\Pictures\*.bmp")
   Do While Len(FN) > 0
       lCnt = lCnt + 1
       ReDim Preserve Files(1 To lCnt)
       Files(lCnt) = "C:\Pictures\" & FN
       FN = Dir
   Loop
   Current = Current + 1
   Current = Current Mod lCnt + 1
   nAction = SPI_SETDESKWALLPAPER
   nSaveChange = SPIF_SENDCHANGE
   strPic = Files(Current)
   lblFile = strPic & Chr(0)
   bRet = SystemParametersInfo(nAction, 0, strPic, nSaveChange)
   If bRet = 0 Then
       bRet = GetLastError
       Dim sError As String
       Dim iErr As Long, dwFormatFlags As Long
       iErr = bRet
       dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_IGNORE_INSERTS + FORMAT_MESSAGE_FROM_SYSTEM
       bRet = FormatMessage(dwFormatFlags, 0, iErr, 0, sError, 0, 0)
       MsgBox "Error: " & iErr & " - " & sError
   End If
Title: Re:Desktop Wallpaper
Post by: iago on October 07, 2003, 11:23 AM
ooh, I get to say this for once!
"eww, visual basic.. can somebody convert it to c++?"
Sorry, I've always wanted to say that :-)


Thanks, Grok!  You're the best! :)
Title: Re:Desktop Wallpaper
Post by: Grok on October 07, 2003, 01:34 PM
The original request did not specify host language for the API call.

You owe me +1.
Title: Re:Desktop Wallpaper
Post by: iago on October 07, 2003, 08:52 PM
Quote from: Grok on October 07, 2003, 01:34 PM
The original request did not specify host language for the API call.

You owe me +1.

haha much like many other posts from people who are looking for help in VB and get in c++ :-P

But I gave you your +1 anyway, making you a nice even 100 :-D
Title: Re:Desktop Wallpaper
Post by: Eibro on October 07, 2003, 10:56 PM
Quote from: Grok on October 07, 2003, 07:21 AM
   Dim Files() As String, FN As String
   Dim lCnt As Long, bRet As Long
   Static Current As Long
   Dim nAction As Long, nSaveChange As Long
   Dim strPic As String
   
   lCnt = 0
   FN = Dir("C:\Pictures\*.bmp")
   Do While Len(FN) > 0
       lCnt = lCnt + 1
       ReDim Preserve Files(1 To lCnt)
       Files(lCnt) = "C:\Pictures\" & FN
       FN = Dir
   Loop
   Current = Current + 1
   Current = Current Mod lCnt + 1
   nAction = SPI_SETDESKWALLPAPER
   nSaveChange = SPIF_SENDCHANGE
   strPic = Files(Current)
   lblFile = strPic & Chr(0)
   bRet = SystemParametersInfo(nAction, 0, strPic, nSaveChange)
   If bRet = 0 Then
       bRet = GetLastError
       Dim sError As String
       Dim iErr As Long, dwFormatFlags As Long
       iErr = bRet
       dwFormatFlags = FORMAT_MESSAGE_ALLOCATE_BUFFER + FORMAT_MESSAGE_IGNORE_INSERTS + FORMAT_MESSAGE_FROM_SYSTEM
       bRet = FormatMessage(dwFormatFlags, 0, iErr, 0, sError, 0, 0)
       MsgBox "Error: " & iErr & " - " & sError
   End If

If i'm not mistaken you need to call LocalFree on sError after you've displayed the error, else you'll leak memory. I know this needs to be done when calling from C/C++; VB should probably be the same though.
Title: Re:Desktop Wallpaper
Post by: hismajesty on October 12, 2003, 07:57 AM
Even though it is VB...maybe it will help some.

http://msdn.microsoft.com/archive/en-us/dnarvbtips/html/msdn_msdn192.asp
Title: Re:Desktop Wallpaper
Post by: WiLD on October 15, 2003, 04:11 AM
Ok dont know if its been answered yet but i got something that works.

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

and the could always make the below show up in a dialog box so u can pick what image.

   SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "C:\BG.GIF", 0


i cant remember where i got this.
Title: Re:Desktop Wallpaper
Post by: -Death- on October 15, 2003, 07:43 PM
Why make one dl it.
Use google here is the link:
http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Season+Changing+Desktop+for+FREE&btnG=Google+Search

I already did must say it is pretty cool. If you really wanted to make ure own just decode one and see what there basis for there desktop changer is..

:-\ :-\
Title: Re:Desktop Wallpaper
Post by: -Death- on October 15, 2003, 07:44 PM
Just copy and paste it won't let u use full link.

>:(  >:(  >:(
Title: Re:Desktop Wallpaper
Post by: Zakath on October 15, 2003, 09:19 PM
Are you incapable of using the proper forum tags? It's incredibly easy to use the "full link." (http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=Season+Changing+Desktop+for+FREE&btnG=Google+Search)
Title: Re:Desktop Wallpaper
Post by: -Death- on October 16, 2003, 04:58 PM
To lazzy it takes to much brain power.
Or.... I just didn't think of that.