|
-
Jun 8th, 2003, 06:38 PM
#1
Thread Starter
Fanatic Member
Change Wallpaper (Resolved)
I'm using this code to choose a random picture from a folder that I have selected and then change the wallpaper to it. The problem is that the wallpaper doesn't actually change. What have I done wrong?
VB Code:
Public 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
Sub Main()
Dim pic() As String
Dim file As String
Dim path As String
Dim count As Integer
Dim i As Integer
Randomize Timer
path = "C:\Windows\Desktop\Graphics\Desktops\"
file = Dir(path)
Do While file <> ""
If file <> "." And file <> ".." Then
ReDim Preserve pic(count)
pic(count) = file
count = count + 1
End If
file = Dir
Loop
i = Round(Rnd * count)
SystemParametersInfo 20, 0, path & pic(i), &H1
End Sub
Last edited by Mushroom Realm; Jun 13th, 2003 at 04:22 PM.
-
Jun 9th, 2003, 06:40 AM
#2
I don't know if this is any help but anyway :
VB Code:
'This project needs
'- a common dialog box
' (To add the Common Dialog Box to your tools menu, go to Project->Components (or press CTRL-T)
' and select Microsoft Common Dialog control)
'- a button
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
Const SPI_SETDESKWALLPAPER = 20
Const SPIF_UPDATEINIFILE = &H1
Private Sub Command1_Click()
'KPD-Team 1998
'URL: [url]http://www.allapi.net/[/url]
'Set the commondialogbox' title
CDBox.DialogTitle = "Choose a bitmap"
'Set the filter
CDBox.Filter = "Windows Bitmaps (*.BMP)|*.bmp|All Files (*.*)|*.*"
'Show the 'Open File'-dialog
CDBox.ShowOpen
'Change the desktop's background
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, CDBox.FileName, SPIF_UPDATEINIFILE
End Sub
Private Sub Form_Load()
Command1.Caption = "Set Wallpaper"
End Sub
Has someone helped you? Then you can Rate their helpful post. 
-
Jun 9th, 2003, 06:46 PM
#3
Thread Starter
Fanatic Member
That's more or less the code that I used. Could the problem be that I'm using a jpeg instead of a bitmap?
*edit*
The problem was that I was using a jpeg. Heres a fix:
VB Code:
Sub Main()
Dim pic() As String
Dim file As String
Dim path As String
Dim count As Integer
Dim i As Integer
Randomize Timer
path = "C:\Windows\Desktop\Graphics\Desktops\"
file = Dir(path)
Do While file <> ""
If file <> "." And file <> ".." Then
ReDim Preserve pic(count)
pic(count) = file
count = count + 1
End If
file = Dir
Loop
count = count - 1
i = Round(Rnd * count)
SavePicture LoadPicture(path & pic(i)), path & "current.bmp"
SystemParametersInfo 20, 0, path & "current.bmp", &H1
End Sub
The code changes the Wallpaper, but how can you make the desktop refresh itself? Right now I'm doing it manually.
*edit*
I tried SendMessage with WM_PAINT, and WM_NCPAINT, and then with both in a row, I sent it to the desktop window but that didn't work. Anyone have any ideas?
Last edited by Mushroom Realm; Jun 9th, 2003 at 09:46 PM.
-
Jun 10th, 2003, 08:25 AM
#4
-
Jun 10th, 2003, 09:11 AM
#5
Is it really that SIMPLE? c'mon.... you're yanking my chain aren't you? I've been looking for that piece of code for some time. Now I cna go back and finish that wall paper flipper I was working on.... Thanks!
-
Jun 10th, 2003, 09:14 AM
#6
-
Jun 10th, 2003, 07:32 PM
#7
Thread Starter
Fanatic Member
It didn't refresh it for me. Well it looked like it refreshed, but it seemed to be refreshing the same image that was laready there, but when I refreshed manually it loaded the new image. I also tried passing GetDesktopWindow() as the hwnd, but that didn't work either.
-
Jun 12th, 2003, 10:32 PM
#8
Thread Starter
Fanatic Member
-
Jun 12th, 2003, 11:44 PM
#9
Stuck in the 80s
I've created a similar program to rotate my wallpaper, and this is the code I use:
VB Code:
Option Explicit
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
Private Const SPIF_SENDWININICHANGE = &H2
Private Const SPIF_UPDATEINIFILE = &H1
Private Const SPI_SETDESKWALLPAPER = 20
Private Sub ChangeWallpaper(sFileName As String)
Dim ret As Long, pPicture As StdPicture
Set pPicture = LoadPicture(sFileName)
SavePicture pPicture, "C:\WINDOWS\TEMP\desktop.bmp"
ret = SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, ByVal "C:\WINDOWS\TEMP\desktop.bmp", _
SPIF_SENDWININICHANGE Or SPIF_UPDATEINIFILE)
End Sub
And it refreshes the desktop for me.
-
Jun 13th, 2003, 04:21 PM
#10
Thread Starter
Fanatic Member
That worked I guess you needed the &H2 in there as well.
-
Aug 4th, 2003, 04:19 AM
#11
With the code The Hobo submitted, how do you tile and center??
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|