Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

create a bitmap for win32

Posted on 2004-11-29
6
Medium Priority
?
540 Views
Last Modified: 2013-12-03
hi there,

normally i would try to do this on myself, but i have very few time these days so i put this into the community.

i need a script that is to be run at windows-startup and that should do the following:

a) determine username and computername
b) create a bitmap with that information (eg. with text "<username> on <computername>" and black background)
c) set that bitmap as the background image (wallpaper)

i know i could solve a) and c) using windows-api, but i have no clue about part b).
i just installed imager.pm and image-magick.pm but did not have time to read their documentation.

any help appreciated,

tx holli

0
Comment
Question by:holli
  • 4
  • 2
6 Comments
 
LVL 6

Author Comment

by:holli
ID: 12696193
p.s.

if one could solve a) without using win-API, it will also be very welcome.
0
 
LVL 5

Expert Comment

by:roee_f
ID: 12700148
Here you go:
#!/usr/bin/perl

use Win32::API;

use constant SPI_SETDESKWALLPAPER  => 20;
use constant SPIF_UPDATEANDSENDINI => 3;
use constant NULL                  => 0;

use Image::Magick;

my $filename = "C:/winnt/logindata.bmp";
$image=Image::Magick->new(size => '400x300');

$rc = $image->Read('xc:white');

#this a. on your question
my $text = "$ENV{USERNAME} on $ENV{COMPUTERNAME}";
# This is b.
$rc = $image->Annotate(
                              text => $text,
                              font => 'Tahoma',
                              fill => 'green',
                              geometry => '+20+30',
                              pointsize => 16);

$rc = $image->Write("$filename");
undef $image;

# This is C.
my $syspinf = Win32::API->new('user32','SystemParametersInfo', [I,I,P,+I], I)
  or die "Could not import function.\n";

$syspinf->Call(SPI_SETDESKWALLPAPER, 0, $filename, SPIF_UPDATEANDSENDIN+I);
0
 
LVL 6

Author Comment

by:holli
ID: 12703589
thank you for your comment.

i tried the script and found that the bitmap produced seems not to be a valid bitmap.
i can view the file with IrfanView but i cannot use it as wallpaper, not even manually.

any idea?
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 6

Author Comment

by:holli
ID: 12703640
i just "saved the file as" (using IrfanView) into a new file and suddenly it works.
maybe the output-format must be especially specified somewhere?
0
 
LVL 5

Accepted Solution

by:
roee_f earned 2000 total points
ID: 12703977
Sorry, you'll have to change one line:
from
$rc = $image->Write("$filename");
to
$rc = $image->Write("bmp2:$filename");

This should do the job.
0
 
LVL 6

Author Comment

by:holli
ID: 12704151
excellent. this does the job.

thank you
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question