Win32::GUIを使用する機会があった。
#!/usr/bin/perl
use Win32::GUI();
# Main Window
$Window = new Win32::GUI::Window (
-name => "Window",
-text => "Window",
-title => "タイトル",
-accel => $acc,
-post => [100, 100],
-size => [300, 300],
);
############################## タイトル
my $font2 = Win32::GUI::Font->new(
#-name => "Comic Sans MS",
-size => 14
);
my $title = $Window->AddLabel(
-text => "タイトル",
-font => $font2,
-top=>10,
-left=>25
);
############################## タイトル2
my $font = Win32::GUI::Font->new(
#-name => "Comic Sans MS",
-size => 12
);
my $label = $Window->AddLabel(
-text => "タイトル2$text",
-font => $font,
-top=>30,
-left=>25
);
#YESボタン###################
$yesButton = $Window->AddButton(
-name => "yesButton",
-text => "YES",
-top => 50,
-left => 25,
);
#NOボタン###################
$noButton = $Window->AddButton(
-name => "noButton",
-text => "NO",
-top => 50,
-left => 75,
);
#結果が表示される場所
$TestTextfield = $Window->AddRichEdit(
-name => "TestTextfield",
-top => 75,
-left => 25,
-readonly => 1,
-multiline => 1,
-vscroll => 1,
-hscroll => 1,
#-addstyle => WS_VSCROLL | WS_HSCROLL | ES_NOHIDESEL,
-width => 250,
-height => 180,
);
$Window->Show();
Win32::GUI::Dialog();
#YESボタンが押された場合の処理
sub yesButton_Click{
$Window->TestTextfield->SetCharFormat(-color => 0x000000);
&main(YES);
}
#NOボタンが押された場合の処理
sub noButton_Click{
$Window->TestTextfield->SetCharFormat(-color => 0x000000);
&main(NO);
}
sub main{
my $flag = shift;
my @s = ("s1","s2","s3","s4","s5");
my $a= $s[int(rand(@s))];
if ($flag eq "YES"){
$TestTextfield->ReplaceSel("$a YES\n");
exit;
}
elsif ($flag eq "NO"){
$TestTextfield->ReplaceSel("$a NO\n");
}
}
スポンサーサイト