Since Tooltip currently isn't working, I wrote what I call a poor man's
tooltip. The subroutines are here:
sub SetupPMTooltip
{
unless ($pmt_text_color = $_[0]) { $pmt_text_color = '[0,0,0]';}
unless ($pmt_bg_color = $_[1]) { $pmt_bg_color = '[255,255,255]';}
}
sub AddPMTooltip
{
my $ref = $_[0];
my $parent = $_[1];
my $text = $_[2];
eval ("\$pmt_left = (\$$ref->Left() + \$$ref->Width());");
eval ("\$pmt_top = \$$ref->Top();");
eval ("\$$parent->AddLabel(-name => 'PMT_$ref', -text => '$text', -left =>
$pmt_left, -top => $pmt_top, -visible => 0, -foreground => $pmt_text_color,
-background => $pmt_bg_color);");
eval ("\$$parent->AddTimer('PMT_$ref"."_Off',0);");
eval ("sub PMT_$ref"."_Off_Timer { \$$parent->PMT_$ref->Hide(); };");
}
sub ShowPMTooltip
{
my $ref = $_[0];
my $parent = $_[1];
eval ("\$$parent->PMT_$ref->Show();");
eval ("\$$parent->PMT_$ref"."_Off->Interval(500);");
}
As you can see, they use a lot of evals, which is ugly, but I haven't been
able to get it to work otherwise.
It works with the MouseMove event, which (as far as I've been able to
determine) only works on subclasses, so you need to make a subclass.
(According to GUI.pm, subclassing only works for Button, Listbox, TabStrip,
and RichEdit.) Here is an example for a Button:
$PMTButton = new Win32::GUI::Class(
-name => "PMTButtonClass",
-extends => "BUTTON",
-widget => "Button",
);
Then you need to assign any controls you want tooltips for to a variable (I
usually don't bother to do this, but you need to for this to work):
$TB = $MainWindow->AddButton(
-class => $PMTButton,
-name => 'TestButton',
-text => 'Test',
-left => 135,
-top => 135,
-width => 30,
-height => 30,
);
Before you can have any tooltips, you must call SetupPMTooltip, which
assigns foreground and background colors for your tips. You can use either
of the valid forms for colors, but they must be surrounded by quotes (they
need to be strings for those ugly evals). You can also call it with no
parameters, in which case it makes the foreground black and the background
white:
SetupPMTooltip('[0,0,0]','[255,255,255]');
Now you can add a tooltip. You must send the following parameters: the name
of the variable for the button (or whatever), the name of the variable for
the parent window, and the text you wish to have in your tooltip. The
variable names must be surrounded by quotes and must not have the '$' in
front (again, this is for those evals):
AddPMTooltip('TB','MainWindow','This is a test');
Now you just define a MouseMove event for your control, and call
ShowPMTooltip from there. You send the variable names just as before, but
don't send the text this time:
sub TestButton_MouseMove
{
ShowPMTooltip('TB','MainWindow');
}
Now when you move the mouse over the control, the tooltip will appear at the
upper right corner of the button. It will disappear one half-second after
you move the mouse away.
Any suggestions for improvement are welcome (especially ways to get rid of
those evals.) Let me know how it works for you if you use it.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com