Changeset 1852

Show
Ignore:
Timestamp:
06/14/06 14:59:38
Author:
miyagawa
Message:

NotifyIcon? support. Create GUI exe

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • thinkpad-saber/trunk/Makefile

    r1850 r1852  
    44 
    55thinkpad-saber.exe: thinkpad-saber.pl 
    6         pp -o thinkpad-saber.exe thinkpad-saber.pl 
     6        pp --icon "resources\tpsaber.ico" --gui -o thinkpad-saber.exe -a resources\tpsaber.ico thinkpad-saber.pl 
    77 
    88thinkpad-saber.zip: 
  • thinkpad-saber/trunk/thinkpad-saber.pl

    r1849 r1852  
    77use File::Spec; 
    88use Win32API::File qw(:ALL); 
     9use Win32::API; 
     10use Win32::GUI (); 
    911use Win32::Sound; 
    1012use Time::HiRes qw(gettimeofday sleep); 
     
    3032$threshold ||= 3.0; 
    3133 
    32 warn "Ready. Waiting for your shake!\n"; 
     34# dummy main window 
     35my $main = Win32::GUI::Window->new( 
     36    -name => 'Main', 
     37    -text => 'ThinkPad Saber', 
     38    -width => 200, 
     39    -height => 200, 
     40); 
     41 
     42my $icon_file = $INC{"PAR.pm"} 
     43    ? do {  
     44        my($fh, $is_new, $fn) = PAR::_tempfile("tpsaber.ico"); 
     45        my $data = PAR::read_file("resources/tpsaber.ico"); 
     46        print $fh $data; 
     47        close $fh; 
     48        $fn; 
     49    } : "resources/tpsaber.ico"; 
     50 
     51my $icon = Win32::GUI::Icon->new($icon_file); 
     52my $notify_icon = $main->AddNotifyIcon( 
     53    -name => 'NI', -id => 1, 
     54    -icon => $icon, -tip => 'ThinkPad Saber', 
     55); 
     56 
     57my $popup = Win32::GUI::Menu->new( 
     58    "" => "SystemMenu", 
     59    ">&Exit" => "Exit", 
     60);  
     61 
     62sub NI_RightClick { 
     63    my($x, $y) = Win32::GUI::GetCursorPos(); 
     64    $main->TrackPopupMenu($popup->{SystemMenu}, $x, $y); 
     65    -1; 
     66
     67 
     68sub Exit_Click { 
     69    exit; 
     70}  
    3371 
    3472sub get_pos { 
     
    79117     
    80118    warn "$mode $dev" if $debug; 
    81     sleep 0.1; 
     119    Win32::GUI::DoEvents(); 
     120    sleep 0.05; 
    82121} 
    83122