I don't like to look up the numeric value of all of the flags every time I want to produce a Win32::MsgBox. Now I don't have to.
#!/perl/bin/perl use strict; use warnings; use Win32; my @pressed = qw( Error OK Cancel Abort Retry Ignore Yes No ); popup('Starting Win32::Msg Demo', ['Information'], 'Demo'); my $output = popup('Should I continue?.', ['YesNo', 'DefaultButton2', +'Question']); print "You pressed '", $pressed[$output], "'\n"; print $output == 6 ? "Continuing now...\n" : "Finished.\n"; my $format = popup("Windows has performed an illegal operation.\nShoul +d I format C:?", ['Critical', 'YesNo'], 'Big Uh Oh'); print $format == 6 ? "Are you nuts?\n" : "It was only a joke!\n"; sub popup { my $option; my $message = shift; my $options = shift; my $title = shift || ''; my %flags = ( OKOnly => 0, # Display OK button only. OKCancel => 1, # Display OK and Cancel buttons. AbortRetryIgnore => 2, # Display Abort, Retry, and Ignore butto +ns. YesNoCancel => 3, # Display Yes, No, and Cancel buttons. YesNo => 4, # Display Yes and No buttons. RetryCancel => 5, # Display Retry and Cancel buttons. Critical => 16, # Display Critical Message icon. Question => 32, # Display Warning Query icon. Exclamation => 48, # Display Warning Message icon. Information => 64, # Display Information Message icon. DefaultButton1 => 0, # First button is default. DefaultButton2 => 256, # Second button is default. DefaultButton3 => 512, # Third button is default. DefaultButton4 => 768, # Fourth button is default. ApplicationModal => 0, # The user must respond to the message b +ox before continuing work in the current application. SystemModal => 4096, # All applications are suspended until t +he user responds to the message box. ); my @options = @{$options}; $option += $flags{$_} for @options; Win32::MsgBox($message, $option, $title); }

In reply to Passing Named Flags to Win32::MsgBox by Mr. Muskrat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.