Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I made a program that selects a random picture from a directory and sets it to the desktop wallpaper. The program runs by reading the directory and making a list of the files then choses a random file and renames it to current.jpg which is the filename I am using for my desktop. Works great but I have to click refresh everytime it runs to see the new wallpaper. Is there anyway to tell windows to refresh the wallpaper, or maybe a better way to do this alltogether?

Replies are listed 'Best First'.
Re: Refreshing Windows desktop
by RhetTbull (Curate) on Apr 10, 2001 at 22:54 UTC
    The following snippet will change the background using a Win32::API call to SystemParametersInfo but note that if the users are using Windows 2000 and ActiveDesktop, the ActiveDesktop background gets layered OVER the normal background so they won't see the change. I'll see if I can find a solution to change the ActiveDesktop background as well and post it here.

    use warnings; use Win32::API; my $SystemParametersInfo = new Win32::API("user32","SystemParametersIn +fo",[ I,I,P,I ],I); if (not defined $SystemParametersInfo ) { die "could not import SystemParametersInfo"; } my $wallpaper = "c:\\winnt\\Blue Lace 16.bmp"; my $action = 20; #reference http://support.microsoft.com/support/kb/ar +ticles/Q97/1/42.ASP to see which constant to use my $saveWinINI = 0; #save this in the user profile? my $param = 0; #dependent on what $action is #change the wallpaper my $retval = $SystemParametersInfo->Call($action,$param,$wallpaper,$sa +veWinINI);
    For more info on SystemParametersInfo look here and here.

      the code doesnt work cannot load win32/api.pm @inc contains e;\perl\lib (ect ect) E: is where perl is and D: is where winnt is... i changed of course the obvious c: to d: in your code....
        Did you install the Win32::API module? If you're using ActiveState perl you can use ppm to install it. I don't recall the exact syntax but I think you can do something like:

        c:\>ppm PPM> install Win32::API PPM> quit
        You could also look here.