modfy the desktopbackground

J

JR

Hi,

how can I change the desktopbackground in vb.net to a JPG file
I can do it with a bmp file with the api
Private Declare Function SystemParametersInfo Lib "user32" Alias
"SystemParametersInfoA" (ByVal uAction As Integer, ByVal uParam As Integer,
ByVal lpvParam As String, ByVal fuWinIni As Integer) As Long

'constants to be used with the above api

Private Const SPI_SETDESKWALLPAPER As Integer = 20

Private Const SPIF_UPDATEINIFILE As Integer = &H1

Private Const SPIF_SendWinIniChange As Integer = &H2


Jan
 
M

Mattias Sjögren

how can I change the desktopbackground in vb.net to a JPG file
I can do it with a bmp file with the api

I believe you need to enable Active Desktop and use its COM API
(IActiveDesktop.SetWallpaper) to use a JPEG image.


Mattias
 
J

Joergen Bech

Why don't you just convert the jpg file to bmp and set
the bmp?

I believe it will take up the same amount of memory once
Windows has to load and present it anyway.

Here is a code sample that takes jpgs:
http://www.codeproject.com/dotnet/SettingWallpaperDotNet.asp

and here:
http://www.devasp.net/net/articles/display/421.html

Both cheat by converting the image to bmp before sending
it to the desktop.

The desktop properties dialog allows you to pick jpg files
and if you rename the file you picked, switch to another background,
then try to select the (now invalid) entry again, it won't work, so
at first sight it does not look like Windows is creating a local bmp
copy from the jpg file selected. But it is. Take a look at
c:\Documents and Settings\<active user name>\Local Settings\
Application Data\Microsoft\ and you will find a file named
"Wallpaper1.bmp", which is the currently selected wallpaper
file converted to bmp. Such a file will not appear if you had
selected a bmp file, as no conversion needs to take place.

I tried the supported formats and only bmp files do not cause
the Wallpaper1.bmp file to be created.

So either you convert the jpg to bmp or Windows will do it for
you. It would appear that the Desktop is not going to take a
jpg directly but needs to go through a cached bmp file.

Yes, you could go the Active Desktop route, but I am sure
your users would not like it.

/Joergen Bech
 
J

JR

thanks all
Joergen Bech @ post1.tele.dk> said:
Why don't you just convert the jpg file to bmp and set
the bmp?

I believe it will take up the same amount of memory once
Windows has to load and present it anyway.

Here is a code sample that takes jpgs:
http://www.codeproject.com/dotnet/SettingWallpaperDotNet.asp

and here:
http://www.devasp.net/net/articles/display/421.html

Both cheat by converting the image to bmp before sending
it to the desktop.

The desktop properties dialog allows you to pick jpg files
and if you rename the file you picked, switch to another background,
then try to select the (now invalid) entry again, it won't work, so
at first sight it does not look like Windows is creating a local bmp
copy from the jpg file selected. But it is. Take a look at
c:\Documents and Settings\<active user name>\Local Settings\
Application Data\Microsoft\ and you will find a file named
"Wallpaper1.bmp", which is the currently selected wallpaper
file converted to bmp. Such a file will not appear if you had
selected a bmp file, as no conversion needs to take place.

I tried the supported formats and only bmp files do not cause
the Wallpaper1.bmp file to be created.

So either you convert the jpg to bmp or Windows will do it for
you. It would appear that the Desktop is not going to take a
jpg directly but needs to go through a cached bmp file.

Yes, you could go the Active Desktop route, but I am sure
your users would not like it.

/Joergen Bech
 
M

Michael M.

Yes,
Windows can not display a jpeg directly on screen, just as media player can
not display an Mpeg movie directly on the on the screen without decoding it,
a filter is always used to decompress it to a bitmap, so even when you load
a jpeg directly it is filtered by a codec into a bitmap in memory and then
displayed.



Mike.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top