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!
: )
Chris Uppal - 26 Jun 2006 11:27 GMT
> 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
jcsnippets.atspace.com - 26 Jun 2006 16:45 GMT
> Hi
>
[quoted text clipped - 8 lines]
> 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
--
http://jcsnippets.atspace.com/
a collection of source code, tips and tricks
Luc The Perverse - 26 Jun 2006 22:54 GMT
>> Hi
>>
[quoted text clipped - 33 lines]
>
> Best regards,
I wonder if there is a simple windows message you could throw to just
refresh the desktop?
I know you can do it easy enough clicking. (Though I am too lazy to
actually change my BMP and try it)
--
LTP
:)
Oliver Wong - 28 Jun 2006 17:35 GMT
> 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
Luc The Perverse - 28 Jun 2006 23:39 GMT
>> 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
[quoted text clipped - 26 lines]
>
> - 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.
--
LTP
:)