Dominik wrote:
i dont get it.. is there one example how to use a simple tooltip - not using the -tip => "text" option but creating a Win32::GUI::Tooltip object somewhere around? I am searching a way to display a "tracking" "multiline" tooltip from one of my events ( a hooked WM_HELP after clicking the helpbutton ) at GetCursorPos coordinates...

Hi Dominik,

I had a look at the tooltip class for the first time this-evening. After reading all the MSDN docs, I think I've got to grips with them, but they are pretty complex beasts.

For multi-line tooltips you MUST set a maximum width.

The example attached shows a couple of ways of setting the tools for a tooltip control and a couple of ways of setting the text. I haven't the time to look at a tracking example right now but here's the basic principle: (1) Add the tool to the tooltip control with the TTF_TRACK and TTF_ABSOLUTE options (-track => 1, -absolute => 1). You won't need to -subclass => 1 option due to (2) and (3) below. (2) Your application become responsible for when to display and hide the tooltip, using the TrackActivate() method. (3) Your application becomes responsible for setting the tooltip position with the TrackPosition() method (probably in a mouse move handler)

You can read all about tooltips and their related tools on msdn at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/tooltip/reflist.asp

Hope this helps.

Regards,
Rob.

#!perl -w
use strict;
use warnings;

use Win32::GUI;

my $mw = Win32::GUI::Window->new(
        -name => "MW",
        -title => "Tooltip test",
        -size => [400,300],
) or die "Failed to create MW";

my $edit = $mw->AddTextfield(
        -name => "TF",
        -pos => [100,100],
        -size=> [100, 20],
) or die "Failed to create TF";

my $tip = Win32::GUI::Tooltip->new(
        $mw,
        -name => "TT",
        -pushexstyle => WS_EX_TOPMOST, # You might get away without this
-onNeedText => \&tooltext, # call to get text for tools with 'needtext' option
) or die "Failed to create TT";

# You need to set a maximum width to use multi-line
# tooltips.  The tip will automatically wrap at this
# width, or you can force a line-break with "\r\n"
$tip->SetMaxTipWidth(100);

# When adding tools, -subclass => 1 is needed, unless
# you want to have to pass mouse messages to the tooltip
# control yourself.

# Add a tool, specifying id and a client area
# rectangle
$tip->AddTool(
        -text => "Some long tip that will wrap\r\nMain Window",
        -subclass => 1,
        -id => 0,
        -rect => [ $mw->GetClientRect() ],
);

# Add a tool, specifying a child window, and specifying
# that we'll return the text from a -onNeedText handler
# (required for multi-line tooltips).
$tip->AddTool(
        -needtext => 1,
        -subclass => 1,
        -window => $edit,
);

$mw->Show();
Win32::GUI::Dialog();
exit(0);

# This sub is called when our tooltip needs to get text
# for a tool.  The tool is identified by the $idFrom
# parameter, but as we've used both mechanisms for
# specifying the tools in this example (by window handle and
# by rect with an id), then we have no way to tell
# whether $idFrom contains a window handle or an id.
sub tooltext
{
        my $self = shift;    # perl tooltip object
        my $idFrom = shift;  # either a window handle or control identifier,
                             # but we can't tell which!

        my $text = "Some text\r\nSome more text";


        return ($text, 0);
        # You need to return a list of a text string
        # and your result code, otherwise you stand a good
        # chance of causing a crash (try returning just the string)
}

Reply via email to