# How to refresh the desktop wallpaper in VB6?



## RedAxl (Nov 17, 2004)

Hi,

I need your help.

Do you know how to refresh the desktop wallpaper in VB6 program without restarting the computer?

I have successfully updated the entry in the the following section in the Registry:
HKEY_CURRENT_USER\Control Panel\Desktop
Wallpaper
WallpaperStyle
TileWallpaper

My problem is, I have to restart the Computer before the changes in Registry takes effect.
Is there a function in advapi32 or anything that can refresh the display without restarting?

Pls help me.

Thanks.
Red


----------



## Mosaic1 (Aug 17, 2001)

Yes there is.


```
' in  the declarations section of the form:

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 Form_Load()

SystemParametersInfo SPI_SETDESKWALLPAPER, 0, _
"C:\windows\clouds.bmp", SPIF_UPDATEINIFILE

End Sub
```
This changes the wallpaper. All you need to do it put in a path and filename. No need to go into the registry first.


----------



## RedAxl (Nov 17, 2004)

Sorry, I forgot to mention. I already used the SystemParametersInfo, but it dont work on Visual Basic 6. It seems that it only works in lower version of VB.


----------



## Mosaic1 (Aug 17, 2001)

It works here. I am running VB6. SPI is very basic.

May we see your code and how you used it?


----------



## Mosaic1 (Aug 17, 2001)

I even wrote a utility for myself which addrssed all those issues and more. It does work to let the System know the Wallpaper has been changed. Then you do have to make the reg changes to get it to tile or whatever.


----------



## RedAxl (Nov 17, 2004)

Yes it works now. Its the picture type that is causing the problem. It works well when I used BMP. But not with JPG format.

Is there a workaround here?

Thanks.


----------



## Mosaic1 (Aug 17, 2001)

Yes and it is exactly what windows does. Convert the jpg to bmp and then it will load as a bmp.

Also, sometimes after you make these changes, ( The tile and stretch) things can get a bit confused if you look in display properties.

Also , if the picture won't change, you can try this next line to first load an empty wallpaper:

```
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "", SPIF_UPDATEINIFILE
```


----------



## RedAxl (Nov 17, 2004)

Ok. Got it! 
Thanks.

One more,  Do you have sample code/script/system call in VB6 that converts JPG to BMP format?

Thanks again! You're Great!


----------



## Mosaic1 (Aug 17, 2001)

Thanks and you're welcome.

Sure. Create a picture box. You can even make it invisible.

Load the picture into it.

Then use savePicture and save it as bmp.

Like this:


```
Private Sub Command1_Click()
SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "", SPIF_UPDATEINIFILE

Picture1.Picture = LoadPicture("Path and filename.jpg")
SavePicture Picture1.Picture, "Path and filename.bmp"

SystemParametersInfo SPI_SETDESKWALLPAPER, 0, "Path and filename.bmp", SPIF_UPDATEINIFILE
End Sub
```
You can do it for gifs and transparent gifs too. To keep the Transparent gif looking transparent, set the background color of the picture box to the same color as the desktop background color and they will look transparent. But if there is too much of a difference in these colors, the gifs can look rough around the edges.


----------



## RedAxl (Nov 17, 2004)

It works! (Y) (B)(B)(B)
It is really good to have expert on my side! ::

Thanks Again!


----------



## Mosaic1 (Aug 17, 2001)

You are very welcome. Although I am no Expert Programmer. Good luck with the rest of your project.


----------



## kara_lahana (Dec 4, 2004)

i have the same problem 
but my wallpaper is not a jpg .It is a html 
what should it do in this situation


----------



## Mosaic1 (Aug 17, 2001)

That's a different animal entirely. 

It makes a change to this key in the registry:
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components

It creates a subkey under Components with several needed Values. If you click the Web Tab in Display Properties and use it manually you will see. I am not sure if or what API to use for this. Do a search on Google and see if you come up with anything,


----------



## kara_lahana (Dec 4, 2004)

Mosaic1 said:


> That's a different animal entirely.
> 
> It makes a change to this key in the registry:
> HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\Desktop\Components
> ...


pefekt if i give the value of GeneralFlags as 1 
i need only make a refresh for desktop und 
the wallpaper is chanced

thanks for help


----------

