CommDlg.pm


NAME

Win32::CommDLg - a Perl interface to the commdlg.dll


DESCRIPTION

Hey, I've been meaning to do this for a while, and I think it's fun. I also hope you'll find it useful.


CONTENTS

FUNCTIONS - CONSTANTS - AUTHOR - BUGS

FUNCTIONS

Alert - Ask - Confirm - GetFilename - GetMultiFilename

Alert
Alert($msg, [$caption]);

Pops a message box on to the screen, with the ! icon and that annoying sound. $msg is what is what you want to say and $caption appears in the head of the message box. $caption defaults to 'Perl Alert'.

Example:

open("<$file") or Alert("Unable to open $file : $!") and die "\n";

Confirm
Confirm($msg, [$caption]);

Pops a message box on to the screen, with the ? icon and an annoying beep. $msg is what is what you want to know and $caption appears in the head of the message box. $caption defaults to 'Perl Confirm'.

The user may chose between a OK or Cancel buttons. Returns true if the user presses OK, false otherwise.

Example:

if(Confirm("Do you really want me to delete $file?")) { unlink($file); }

Ask
Ask($msg, [$caption]);

Pops a message box on to the screen, with the ? icon and an annoying noise. $msg is what is what you want to know and $caption appears in the head of the message box. $caption defaults to 'Perl Question'.

The user may chose between a Yes or No buttons. Returns true if the user presses Yes, false otherwise.

Example:

$fries=Ask("Do you want fries with that?");

GetFilename
GetFilename([$dir, $caption])

Prompt the user for a file name those cool Explorer style dialog boxes. $dir is the directory to start looking in (default is cwd) and $caption is what goes in the title (default is 'Open file'). Returns the full pathname to the file, or nada if the user pressed Cancel.

Example:

$file=GetFilename('', 'Where are the crown jewels?'); if($file) { Confirm("Are you sure there here?\n$file"); }

GetMultiFilename
GetMultiFilename([$dir, $caption])

Prompt the user for several file names those cool Explorer style dialog boxes. $dir is the directory to start looking in (default is cwd) and $caption is what goes in the title (default is 'Open file'). Returns an array of full pathnames to the files, or an empty array if the user pressed Cancel.

Example:

@files=GetMultiFilename('c:\', 'Files to delete'); print "Bwahahaha!\n" foreach $file (@files) { unlink $file; }

CONSTANTS

$ID, $MB, $OFN

COMMDLG.H has more constants than you can shake a stick at. Rather than exporting them into your name space, I set up so little objects that magically AUTOLOAD from the Win32::CommDlg namespace. $ID->YES will return the IDYES constant, $MB->ICONEXCLAIM is MB_ICONEXCLAIM, and so on. These objects are smart enough that they won't choke on $ID->IDCANCEL, if you type that my accident.

You may also import the constants with the :ID_FLAGS, :MB_FLAGS and :OFN_FLAGS import tags. In which case the constants are accessed via &MB_YESNO, which is better than &Win32::CommDlg::MB_YESNO, but only just.

BTW, this is an idea I thought up all by my lonesome. And I'm somewhat proud of it -:)

Example:

    if(MessageBox("Here's something very interesing.", $0,
                    $MB->YESNO|$MB->ICONEXCLAMATION|$MB->TASKMODAL)==$ID->YES)
    {
        print <<HERE;
    \$MB->YESNO=@{[$MB->YESNO]}
    \$MB->ICONWARNING=@{[$MB->ICONWARNING]}
    \$ID->YES=@{[$ID->YES]}
    \$ID->ABORT=@{[$ID->ABORT]}
    \$ID->CANCEL=@{[$ID->CANCEL]}
    HERE
    }