Kristofer Wolff wrote:
> hi,
> does anyboys know, how to set the Windows backgroundimage on a
> desktop ?
Briefly tested (not -u option):
#!perl -w --
use strict;
use Win32::API;
our %A;
for (my $ii = 0; $ii < @ARGV; ) { # get switches
last if $ARGV[$ii] =~ /^--$/;
if ($ARGV[$ii] =~ /^-{1,2}(.*)$/) {
splice @ARGV, $ii, 1; # remove arg
my $tmp = $1;
if ($tmp =~ /^([\w]+)=(.*)$/) {
$main::A{$1} = $2;
} else {
$main::A{$1}++;
}
} else {
$ii++;
}
}
my $usage = <<EOD;
Usage: $0 [-u] <file.bmp>
-u update winini for next reboot
<file.bmp> a BMP file to set wallpaper to
EOD
die $usage if $A{h} or $A{help};
my $bmp = 'C:\Windows\Plus!.bmp'; $bmp = $ARGV[0] if @ARGV;
my $update = 0; $update = 1 if $A{u};
if (not -e $bmp) { # check if BMP exists
print "BMP '$bmp' does not exist\n";
exit 2;
}
print "Setting wallpaper to '$bmp'; update=$update\n";
SetWallpaper ($bmp, $update);
exit;
#- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sub SetWallpaper {
my $bmp = shift;
my $update_ini = shift || 0;
my $SystemParametersInfo = new Win32::API("User32", "SystemParametersInfo",
[qw(I I P I)], 'N') or die 'Get SystemParametersInfo: ' .
Win32::FormatMessage(Win32::GetLastError());
use constant SPI_SETDESKWALLPAPER => 20;
use constant SPIF_SENDWININICHANGE => 2;
use constant SPIF_UPDATEINIFILE => 1;
my $fWinIni = SPIF_SENDWININICHANGE;
$fWinIni |= SPIF_UPDATEINIFILE if $update_ini; # untested
my $result = $SystemParametersInfo->Call(SPI_SETDESKWALLPAPER, 0, $bmp,
SPIF_SENDWININICHANGE) or die 'Call SystemParametersInfo: ' .
Win32::FormatMessage (Win32::GetLastError ());
}
__END__
--
,-/- __ _ _ $Bill Luebkert ICQ=162126130
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // http://dbecoll.tripod.com/ (Free site for Perl)
-/-' /___/_<_</_</_ Castle of Medieval Myth & Magic http://www.todbe.com/
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs