Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^2: Win32::SysTray Issue

by pryrt (Abbot)
on Oct 22, 2020 at 17:05 UTC ( [id://11123054]=note: print w/replies, xml ) Need Help??


in reply to Re: Win32::SysTray Issue
in thread Win32::SysTray Issue

For example,
#!perl # # [id://11122933] use 5.012; # strict, // use warnings; use Win32::SysTray; use Win32 qw/MB_ICONEXCLAMATION MB_ICONSTOP MB_ICONQUESTION MB_ICONINF +ORMATION/; $| = 1; my $tray = new Win32::SysTray ( 'icon' => 'C:\images\logo.ico', 'single' => 1, ) or exit 0; # each row of @choices needs a hashref, with the keys name, text, and +action -- name should be a perl-safe-identifier (single word), text i +s visible string, and action is a coderef my @choices = ( { name => 'EmployeeManagement', text => 'Employee Management', act +ion => sub { Win32::MsgBox("Do some management task", 0 | MB_ICONINFO +RMATION, 'Employee Management')} }, { name => 'Quit', text => 'Quit', action => sub { print "Exiting p +er user request\n"; exit 0 } }, ); my $DIALOG = create_dialog(); $tray->setMenu ( "> Show &Dialog" => sub { $DIALOG->Show() }, # can re-show +the dialog, too ">-" => 0, "> E&xit" => sub { return -1 }, ); $DIALOG->Show(); # if you want this dialog to default to visible; o +therwise, remove this line and rely on the tray to start it Win32::GUI::Dialog(); exit; sub create_dialog { my $dlg = Win32::GUI::DialogBox->new( -name => 'DlgBox', -text => 'Option Menu', -width => 300, -height => 120 + 20*@choices, ); $dlg->AddLabel( -text => 'Please make a selection', -pos => [15,10], -size => [$dlg->ScaleWidth() - 30 , 30], ); $dlg->AddButton( -text => 'Ok', -default => 1, -ok => 1, -size => [60,20], -pos => [$dlg->ScaleWidth() - 140, $dlg->ScaleHeight - 30], -onClick => \&DlgBox_Process, ); $dlg->AddButton( -text => 'Cancel', -cancel => 1, -size => [60,20], -pos => [$dlg->ScaleWidth() - 70, $dlg->ScaleHeight - 30], -onClick => \&DlgBox_Terminate, ); my $top = 50; for my $opt ( @choices ) { $dlg->AddRadioButton( -name => $opt->{name}, -size => [15,15], -pos => [15, $top], ); $dlg->AddLabel( -text => $opt->{text}, -pos => [45, $top], -size => [$dlg->ScaleWidth() - 45 - 10,15], ); $top += 20; } return $dlg; } sub DlgBox_Process { my $action = undef; for my $opt ( @choices ) { if( $DIALOG->{$opt->{name}}->Checked()) { $action = $opt->{action}; last; } } if(defined $action) { $DIALOG->Hide(); $action->(); #$DIALOG->Show(); # un-comment to automatically re-show the ma +in input dialog } else { Win32::MsgBox("Programmer needs to define action!", 0 | MB_ICO +NEXCLAMATION, 'ERROR in Management Dialog!') } return 0; } sub DlgBox_Terminate { $DIALOG->Hide(); return 0; }

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11123054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2024-04-18 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found