Possible to change user's desktop background (Windows)

G

Guest

Hi

I haven't touched Java for two years and this evening I suddenly came up
with an idea I'd like to try and get working - but can't think for the life
of me how to do it. Basically the program will be for myself (ie
administrator over my own machine - windows 2000). Essentially I need to
work out how to change my desktop background. Is this allowed in Java? Or is
there some kind of security level in the way to prevent this from happening?
If it is allowed, which methods and classes am I likely to need?

Many thanks to anyone who can answer this and ease me back into this
programming malarky gently!

: )
 
C

Chris Uppal

Essentially I need to
work out how to change my desktop background. Is this allowed in Java? Or
is there some kind of security level in the way to prevent this from
happening? If it is allowed, which methods and classes am I likely to
need?

There's no straightforward way of doing that. It's not that it's forbidden,
but setting the wallpaper is part of Windows, and Java doesn't attempt to be a
Windows-specific programming language. So you don't have direct access to any
of the Windows APIs.

You could do this via JNI, but that's rather complicated, and you don't sound
as if you want that kind of complication. A better idea, if you know a little
C -- or if you know someone who does, and who can compile stuff on Windows --
would be to create a small command-line program that does the actual setting
(using the Win32 API) and which you invoke using one of the variations on
Runtime.exec().

This link seems to be a reasonable discussion, and includes some simple C code
at the end.

http://answers.google.com/answers/threadview?id=512662

Other examples can be found by searching for: "SPI_SETDESKWALLPAPER".

-- chris
 
J

jcsnippets.atspace.com

Hi

I haven't touched Java for two years and this evening I suddenly came up
with an idea I'd like to try and get working - but can't think for the life
of me how to do it. Basically the program will be for myself (ie
administrator over my own machine - windows 2000). Essentially I need to
work out how to change my desktop background. Is this allowed in Java? Or is
there some kind of security level in the way to prevent this from happening?
If it is allowed, which methods and classes am I likely to need?

Many thanks to anyone who can answer this and ease me back into this
programming malarky gently!

Apart from the solution Chris already gave you, here is a quick & (real)
dirty approach I once used when I started programming.

Because I did not know how to do it using whatever API was available, I just
created an initial background image called "background.bmp", which I set as
wallpaper.

Each time my computer started, a program would run which would copy a new
background over the existing file. Since Windows had already loaded the
previous wallpaper, it would not show directly, but it would show the next
time I rebooted the machine.

So in the end I got what I want: each time I started my machine, I had a new
wallpaper.

Far from an ideal solution, but I was happy with it at the time ;)

Best regards,

JayCee
 
O

Oliver Wong

I haven't touched Java for two years and this evening I suddenly came up
with an idea I'd like to try and get working - but can't think for the
life
of me how to do it. Basically the program will be for myself (ie
administrator over my own machine - windows 2000). Essentially I need to
work out how to change my desktop background.

Here's another potentially interesting solution:

Back in the days of Windows 95, you could have something called an
"Active Desktop" which basically meant instead of an image, your "wallpaper"
was an HTML document (I don't know if this feature is still available in
Win2K or WinXP). What you could do is create an HTML document which simply
fills itself entirely with an applet. Then, you'd write an applet which
randomly chooses an image and paints it to its graphic device. This will
result in painting that image to the entire of your Active Desktop, thus
emulating a wallpaper.

Obviously, this is pretty wasteful, but with this solution you can
actually do some fancy stuff like changing the desktop every minute with
animated transitions, or having the desktop image react to movements of your
mouse cursor.

I did this a long time ago (back when I was still running Win95), and
the performance was not great, but it was passable... I eventually turned it
off and went for a static background, because I felt the performance hit
wasn't worth the extra eye candy. It might perform better now with
enhancements to the JVM, and faster CPU speeds.

- Oliver
 
L

Luc The Perverse

Oliver Wong said:
Here's another potentially interesting solution:

Back in the days of Windows 95, you could have something called an
"Active Desktop" which basically meant instead of an image, your
"wallpaper" was an HTML document (I don't know if this feature is still
available in Win2K or WinXP). What you could do is create an HTML document
which simply fills itself entirely with an applet. Then, you'd write an
applet which randomly chooses an image and paints it to its graphic
device. This will result in painting that image to the entire of your
Active Desktop, thus emulating a wallpaper.

Obviously, this is pretty wasteful, but with this solution you can
actually do some fancy stuff like changing the desktop every minute with
animated transitions, or having the desktop image react to movements of
your mouse cursor.

I did this a long time ago (back when I was still running Win95), and
the performance was not great, but it was passable... I eventually turned
it off and went for a static background, because I felt the performance
hit wasn't worth the extra eye candy. It might perform better now with
enhancements to the JVM, and faster CPU speeds.

- Oliver

The overhead and instability of Active Desktop was unspeakable. It may
have improved a little, but I don't think it is very good.

But keeping a giant screen size applet alive all the time, just to change
background images seems . . .wasteful.
 

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

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top