Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1692921
  • 博文数量: 362
  • 博客积分: 10587
  • 博客等级: 上将
  • 技术积分: 4098
  • 用 户 组: 普通用户
  • 注册时间: 2009-09-10 18:15
文章分类

全部博文(362)

文章存档

2014年(1)

2013年(58)

2011年(115)

2010年(112)

2009年(76)

分类: PERL

2013-03-08 22:01:24

PerlMonks_tutorial_2.pl

  1. #!/usr/bin/perl

  2. #author: zhengsenlin
  3. #date: 2013-03-06
  4. #desc: Wx ok

  5. use 5.016;
  6. use strict;
  7. use warnings;
  8. use autodie;
  9. use Wx;

  10. package MyApp;
  11. use base 'Wx::App';

  12. sub OnInit {
  13.     my $this = @_;
  14.     my $frame = MyFrame->new("Mini-image demo", [-1, -1], [650, 850]);
  15.     unless($frame) {print "unable to create frame -- exiting."; return undef}
  16.     $frame->Show(1);
  17. }

  18. package MyFrame;
  19. use base 'Wx::Frame';
  20. use Wx qw(wxWidth wxHeight);
  21. #use Wx::Image;
  22. use IO::File;

  23. sub new {
  24.     my $class = shift;
  25.     my $this = $class->SUPER::new(undef, -1, $_[0], $_[1], $_[2]);
  26.     my $file = IO::File->new("12062817554.jpg", "r");
  27.     binmode $file;

  28.     my $handler = Wx::JPEGHandler->new();
  29.     my $image = Wx::Image->new();
  30.     my $bmp;
  31.     $handler->LoadFile($image, $file);
  32.     $bmp=Wx::Bitmap->new( $image );
  33.     if ($bmp->Ok()) {
  34.         $this->{ImageViewer} = Wx::StaticBitmap->new($this, -1, $bmp);
  35.     }

  36.     my $b1 = Wx::LayoutConstraints->new();
  37.     $b1->left->Absolute(0);
  38.     $b1->top->Absolute(0);
  39.     $b1->width->PercentOf($this, wxWidth, 650);
  40.     $b1->height->PercentOf($this, wxHeight, 850);

  41.     $this->{ImageViewer}->SetConstraints($b1);
  42.     $this;

  43. }

  44. package main;
  45. my $app = MyApp->new();
  46. $app->MainLoop();


阅读(892) | 评论(0) | 转发(0) |
0

上一篇:PerlMonks_tutorial_1

下一篇:Wx Button atction

给主人留下些什么吧!~~