PerlMonk
渐入佳境
帖子: 49 注册时间: 2016年09月19日 10:20
联系:
帖子
由 PerlMonk » 2017年04月22日 19:09
[Perl] Win32::GUI 模块安装、配置以及学习路线 序
我可能用了假的 Perl 环境,各种模块安装失败的经历。已改用 Strawberry Perl
相关链接 模块安装
Activeperl V5.16 StrawberryPerl V5.24 Portable
CPAN install Win32::GUI 安装失败,改从源码包安装
执行 portableshell.bat
进入 Win32::GUI 源码包解压目录
perl Makefile.pl
dmake
dmake install
没有明显问题(但好像缺少 DIBitmap、Grid、AxWindow 组件)
通过 cpan install Win32::GUI::Grid 安装失败
从 Grid 源码包目录安装提示:
Win32::GUI::Grid can only be built using MSVC, not 'gcc',
as it requires the MFC framework.
Win32::GUI::Grid will be skipped during the current build process.
先欠着吧,总不能为了环境配置花太多时间
StrawberryPerl V5.10.2 Portable
考虑到官网给出了针对 Perl 5.10 的 PPM 安装包 Win32-GUI-1.06-PPM-5.10.zip
无需dmake,也就没有各种头痛的问题,所以我下载了 草莓Perl V5.10
执行 portableshell.bat,
进入 Win32-GUI-1.06-PPM-5.10.zip 解压目录,
ppm install Win32-GUI.ppd
安装完成。带有 Grid , DIBitmap, AxWindow
学习资料
在线文档 离线文档
模块安装目录下的有着各种文档 C:\Strawberry\perl\site\lib\Win32
这些文档可以通过 perldoc 命令直接查阅,有些是教学,有些是针对特定组件的说明
perldoc Win32::GUI
perldoc Win32::GUI::Tutorial
perldoc Win32::GUI::Tutorial::Part1
perldoc Win32::GUI::UserGuide
组件类的文档比如:
perldoc Win32::GUI::Button
perldoc Win32::GUI::Preference::Options
不过这种终端显示的文档会丢失不同文档之间的依赖链接,所以还是生成 HTML 为好。
pod文档批量遍历生成 HTML 运行示例程序
C:\Strawberry\perl\site\bin\win32-gui-demos.pl
C:\Strawberry\perl\site\lib\Win32\GUI\demos
[Finished in 0.2s]
上次由
PerlMonk 在 2017年04月27日 22:17,总共编辑 1 次。
PerlMonk
渐入佳境
帖子: 49 注册时间: 2016年09月19日 10:20
联系:
帖子
由 PerlMonk » 2017年04月27日 20:39
use Win32::GUI();
# 创建窗口
my $main = Win32::GUI::Window->new(
-name => 'Main',
-width => 100,
-height => 100,
);
# 在窗口中添加 label(就是文本),默认为与左上方
$main->AddLabel( -text => "Hello, world" );
# 展现窗口
$main->Show();
# 进入 dialog 事件循环
Win32::GUI::Dialog();
# 事件循环结束后,退出脚本
exit(0);
# 结束 'Main'窗口的事件循环,返回 -1,并将控制权返还给 perl
sub Main_Terminate { return -1 }
这里 exit(0) 可以去掉
但 Main_Terminate { return -1 } 应保留,否则关闭窗口后无法结束循环、返回控制权
vicyang
版主
帖子: 56 注册时间: 2016年07月21日 20:35
联系:
帖子
由 vicyang » 2017年05月24日 11:29
脚本保存为 utf8 编码格式
use utf8;
use Encode;
use Win32::GUI();
$text = encode('gbk', "文本测试");
$main = Win32::GUI::Window->new(
-name => 'Main',
-text => 'Perl',
-size => [200, 100],
);
$font = Win32::GUI::Font->new(
-name => encode('gbk', "微软雅黑"),
-size => 24,
);
$label = $main->AddLabel(
-text => $text,
-font => $font,
-foreground => [255, 0, 0],
);
$main->Show();
Win32::GUI::Dialog();
sub Main_Terminate {
-1;
}
正浏览此版面之用户: Ahrefs [Bot] 和 0 访客