create a bitmap for win32

Posted on 2004-11-29
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 and but did not have time to read their documentation.

any help appreciated,

tx holli

Question by:holli
    LVL 6

    Author Comment


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

    Expert Comment

    Here you go:

    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";

    LVL 6

    Author Comment

    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?
    LVL 6

    Author Comment

    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?
    LVL 5

    Accepted Solution

    Sorry, you'll have to change one line:
    $rc = $image->Write("$filename");
    $rc = $image->Write("bmp2:$filename");

    This should do the job.
    LVL 6

    Author Comment

    excellent. this does the job.

    thank you

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (,  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
    There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
    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…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

    758 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now