Jason P. wrote:
Robert May wrote:
In the example provided, and all my further tests, using the subclass
option provides inaccurate location for the automated placement. Try
moving the window down a ways. You will find you need to expand the window.
It looks like the subclass option is using screen x,y vs where it should
be using window x,y. More likely the conversion was not realized
somewhere in the code, as I doubt anyone did this intentionally.
I noticed this (and the report in your earlier post of the tooltip
window appearing under the textfield), but didn't have time to
investigate yesterday. It turns out that the co-ordinates are bing sent
correctly, but that the control is being created incorrectly as a child
winodow (hence expects its co-ordinates relative to it's parent's client
area) when it should be a top-level owned window. I've raised a
tracker, and will fix in the next release.
And I hate to be a pain, but I can't get my head around how to use the
TrackActivate and TrackPosition methods appropriately.
OK, as I was interested in seeing this work too, here's an example.
There may well be easier ways to achieve this.
Rob.
#!perl -w
use strict;
use warnings;
use Win32::GUI;
sub TME_LEAVE() {2};
sub OFFSET_X() {16};
sub OFFSET_Y() {16};
my $mw = Win32::GUI::Window->new(
-name => "MW",
-title => "Tracking Tooltip",
-size => [400,300],
-onMouseMove => \&displayTooltip,
-onMouseOut => \&hideTooltip,
) or die "Failed to create MW";
my $tip = Win32::GUI::Tooltip->new(
$mw,
-name => "TT",
-pushexstyle => WS_EX_TOPMOST, # You might get away without this
) or die "Failed to create TT";
# Add a tool, specifying id and a client area
# rectangle
$tip->AddTool(
-text => "",
-id => 1001,
-rect => [ $mw->GetClientRect() ],
-track => 1,
-absolute => 1,
);
$mw->Show();
Win32::GUI::Dialog();
exit(0);
sub displayTooltip
{
my ($win, $cx, $cy) = @_; # x,y in client co-ordinates
# Take into account that client co-ordinates can be negative,
# the need to do this will go when tracker 1262098 is fixed
$cx -= 65536 if $cx > 32767;
$cy -= 65536 if $cy > 32767;
# convert pos to screen co-ordinates
my ($sx, $sy) = $win->ClientToScreen($cx, $cy);
# Update the tip text to the co-ordinates of the mouse
$win->{TT}->UpdateTipText(1001,"Screen:$sx,$sy Client:$cx,$cy");
# Update tooltip position to an offset from the mouse position
$win->{TT}->TrackPosition($cx + OFFSET_X, $cy + OFFSET_Y);
# TODO: will need to be $sx, $sy when tracker
# 1273134 is fixed
# Show the tooltip
$win->{TT}->TrackActivate(1001,1);
# Set up mouse tracking so we get an onMouseOut event when we
# leave the window
$win->TrackMouse(0, TME_LEAVE);
return;
}
sub hideTooltip
{
my ($win) = @_;
# Hide the tooltip
$win->{TT}->TrackActivate(1001,0);
return;
}