Submitting these values to Show in regards to a window does not always work appropriately????
"$win->Show(SW_SHOWNA);"

Herein lies an example sccript, along with an attached .ico file for use with said script.

Sometimes it fires the Activate, sometimes it doesnt...odd, and annoying to have it grab the cursor away, if only for brief moments, It can stop you typing at just the right time..

WinXP Pro SP2
AS perl 5.8.4 build 810
Win32::GUI 1.02

Any help in sorting out why its pissy/not working properly would be appreciated!

#-snip-#
use warnings;
use strict;

use Win32::GUI;

# winuser.h constants.
#-- both are supposed to make it so the window is shown, but not activated.
use constant SW_SHOWNOACTIVATE => 4;
use constant SW_SHOWNA => 8;

# collapsing length (milliseconds)
use constant COLLAPSE_TIME => 100;

# shell window handle
my ($DOS) = Win32::GUI::GetPerlWindow();

# Functional States
my $isActive = 1;
my $isPopable = 1;

# Collapsing Controls
my $lapseTime = 0;
my $lapsePart = 0;
use constant LAPSE_TIME  => 100;
use constant LAPSE_PARTS => 10;

# This window is created and never shown/activated/enabled, as a means to NOT show the notification on the taskbar. (needs a parent != desktop)
my $winDiscard = new Win32::GUI::Window(
   -name=>'winGarbage',
   -height => 0,
   -width => 0,
   -remstyle => 0xFFFFFFFF, #make borderless
   -addstyle => 0x80000000 | 0, #make borderless
   -minimizebox=>0,
   -maximizebox=>0,
   -sizeable=>1,
   -resizable=>0,
   -menubox=>0,
   -sysmenu=>1,
   -dialogui=>0,
); # the better part of these options are purely here because I copied them from below.

my $win = new Win32::GUI::Window(
   -parent=>$winDiscard,
   -name =>'winPopNotify',
   -height => 20,
   -width => 200,
   -topmost => 1,
   -remstyle => 0xFFFFFFFF, #make borderless
   -addstyle => 0x80000000 | 0, #make borderless
   -minimizebox=>0,
   -maximizebox=>0,
   -sizeable=>1,
   -resizable=>0,
   -menubox=>0,
   -sysmenu=>1,
   -dialogui=>0,
);

# add Show Timer
my $stimer = $win->AddTimer('tShow',30*1000); #30 seconds

# add Collapsing Timer
my $ctimer = $win->AddTimer('tCollapse',COLLAPSE_TIME);

# Create NotifyIcon
my $icon = new Win32::GUI::Icon('stupid.ico');
my $ni = $win->AddNotifyIcon(-name => 'NI', -id=>1, -tip=>'PopNotifyContol', -icon=>$icon);

# Create richedit (content)
my $re = $win->AddRichEdit(
   -name => 'rePNContent',
   -height => ($win->GetClientRect)[3],
   -width =>    ($win->GetClientRect)[2],
);

# Create NI Menu
my $NI_NO_MENU = 0;
my $Menus = $winDiscard->AddMenu(
   -name => 'MMMenus',
);
my $MTray = $Menus->AddMenuButton(
   -name => 'MTray',
);
my $MTShowStatus = $MTray->AddMenuItem(
   -name => 'MTShowStatus',
   -text => 'Show Status',
   -id   => 3,
   -onClick => \&MTShowStatus_Toggle,
);
my $MTPopup = $MTray->AddMenuItem(
   -name => 'MTPopup',
   -text => 'Popup',
   -id   => 2,
   -onClick => \&MTPopup_Toggle,
);
$MTray->AddMenuItem(
   -seperator => 1,
   -id   => 1,
);
my $MTExit = $MTray->AddMenuItem(
   -name => 'MTExit',
   -text => 'Exit',
   -id   => 0,
   -onClick => \&MTExit,
);

# Prep content
$win->rePNContent->BackColor('#000000');
$win->rePNContent->SetCharFormat(-color=>'#FFFF00');
$win->rePNContent->Select(-1,-1);
$win->rePNContent->ReplaceSel("Notification\nPopup\n");

# Prep NI menu
$MTShowStatus->Checked($isActive);
$MTPopup->Checked($isPopable);
$MTPopup->Enabled($isActive);


# Hide the shell window
#- disabled for debug
# Win32::GUI::Hide($DOS);

# Adjust the position of the Popup
ResizeWindow();

# Show the popup without activation.
$win->Show(SW_SHOWNA);
$win->Enable(0);

# Begin GUI Event Loop
Win32::GUI::Dialog();

# Show the shell window
Win32::GUI::Show($DOS);


#########################################################################3
# routines
sub AdjustWindow{
   my ($edge, $need) = FindTrayEdge();
   #- Debug
   # print "On edge [b/r/t/l]:$edge\nEdge is: $need\n";
   if($edge == 1){
       $win->Left(Win32::GUI::GetSystemMetrics(SM_CXSCREEN) - $win->Width);
       $win->Top( $need - $win->Height);
   }
   if($edge == 2){
       $win->Left($need - $win->Width);
$win->Top( Win32::GUI::GetSystemMetrics(SM_CYSCREEN) - $win->Height);
   }
   if($edge == 3){
       $win->Left(Win32::GUI::GetSystemMetrics(SM_CXSCREEN) - $win->Width);
       $win->Top( $need);
   }
   if($edge == 4){
       $win->Left($need);
$win->Top( Win32::GUI::GetSystemMetrics(SM_CYSCREEN) - $win->Height);
   }
   return undef;
}


sub ResizeWindow{
my $lines = $win->rePNContent->LineFromChar($win->rePNContent->TextLength());
   my $lsize = 14; # derive formula for proper size. Anyone have this?
   $win->Height( ($lines * $lsize) + 4);
   $win->rePNContent->Height($win->Height);
   AdjustWindow();
   return undef;
}

##++
# Show Timer events
sub tShow_Timer{
   $lapseTime=0;
   if($isActive){
       ResizeWindow();
       $win->Show(SW_SHOWNA);
   }
}
#--

##++
# Collapse Timer events
sub tCollapse_Timer{
   if($win->IsVisible && $isPopable){
       if($lapseTime < LAPSE_TIME){
           #wait to shrink
           $lapseTime++;
           if($lapseTime == LAPSE_TIME){
               $lapsePart= int($win->Height() / LAPSE_PARTS);
               #- Debug
               # print $win->Height(), ':',LAPSE_PARTS(),":$lapsePart\n";
           }
       }elsif($lapseTime < LAPSE_TIME+LAPSE_PARTS){
           # window shrank towards hiding.
$win->Height($lapsePart * (( LAPSE_TIME + LAPSE_PARTS ) - $lapseTime) );
           AdjustWindow();
           $lapseTime++;
       }elsif($lapseTime == LAPSE_TIME + LAPSE_PARTS){
           #window to be closed completely
           $win->Hide();
           $lapseTime=0;
       }
   }
}
##--

##++
# Window events
sub winPopNotify_Activate{
   print "Why am I activating!\n";
   return 1;
}

sub winPopNotify_Terminate{
   $win->rePNContent->DESTROY;
   $win->NI->Delete(-id => 1);
   return -1;
}
##--

##++
# Menu Actions.
sub MTShowStatus_Toggle{
   $isActive^=1;
   if($isActive){
       $MTShowStatus->Checked(1);
       $MTPopup->Enabled(1);
       $win->Show(SW_SHOWNA);
       ResizeWindow();
       $lapseTime=0;
   }else{
       $MTShowStatus->Checked(0);
       $MTPopup->Enabled(0);
       $win->Hide();
   }
}

sub MTPopup_Toggle{
   $isPopable^=1;
   if($isPopable){
       $MTPopup->Checked(1);
   }else{
       $MTPopup->Checked(0);
       if($isActive){
           $win->Show(SW_SHOWNA);
           ResizeWindow();
           $lapseTime=0;
       }
   }
}


sub MTExit{
   winPopNotify_Terminate();
}
##--

##++
# NotifyIcon Events
sub NI_RightClick{
   #Display menu
   my($x, $y) = Win32::GUI::GetCursorPos();
   if(!$NI_NO_MENU){
       $win->TrackPopupMenu($MTray, $x, $y);
   }else{
       $NI_NO_MENU = 0;
   }
   return 1;
}

sub NI_Click{
   #- Debug
   print "toggle\n";
   MTShowStatus_Toggle;
   return 1;
}
##--

##++
# TaskBar location function
sub FindTrayEdge{
   # Get the window of the windows Taskbar
   my $tray = Win32::GUI::FindWindow("Shell_TrayWnd","");
# Get the Absolute dimensions of the Taskbar
   my ($al,$at,$ar,$ab) = Win32::GUI::GetAbsClientRect($tray);
# Get the screen dimentions.
   my $CX = Win32::GUI::GetSystemMetrics(SM_CXSCREEN);
   my $CY = Win32::GUI::GetSystemMetrics(SM_CYSCREEN);
#- Purely informational debug
   # print "Screen Res: $CX x $CY\n";
   # print "Taskbar Dims: absolute($al,$at,$ar,$ab)\n";
my $retval1=-1;
   if($ar+2 >= $CX && $ab+2 >= $CY){
       #bottom
       $retval1 = 1;
   }
   if($al-2 > 0){
       #right
       $retval1 = 2;
   }
   if($ar+2 >= $CX && $ab+2 < $CY){
       #top
       $retval1 = 3;
   }
   if($al-2 <= 0 && $ar+2 < $CX){
       #left
       $retval1 = 4;
   }
my $retval2=-1;
   if($retval1 == 1){
       #bottom
       $retval2 = $at-2;
   }elsif($retval1 == 2){
       #right
       $retval2 = $al-2;
   }elsif($retval1 == 3){
       #top
       $retval2 = $ab+2;
   }elsif($retval1 == 4){
       #left
       $retval2 = $ar+2;
   }
# return edge[-1,1..4],postion[-1,pixel of appropriate edge.(approx)]
   return $retval1,$retval2;
}
##--

############################################################
# end
1;

#-snip-#

<<inline: stupid.ico>>

Reply via email to