Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Toolbar button's tooltip text

162 views
Skip to first unread message

Jatin

unread,
Apr 19, 2008, 5:16:57 PM4/19/08
to
I have handle to a toolbar and I need to get the tooltip text of each of
the tools buttons on it. I am attempting to get the tooltips using
following way:

tooltipHandle := SendMessage(hToolbarHandle, TB_GETTOOLTIPS, 0, 0);

Above gets me the handle to the tooltips control for the toolbar. But
beyond that I am clueless as to how to get the tooltip text for each of
the tool buttons on this toolbar. I have Googled but haven't found
anything except that I should send TTM_GETTEXT message to the tooltip
control as follows:

var
tooltipHandle : tHandle;
toolTipInfo : TToolInfo;
pText : array[0..16000] of char;

toolTipInfo.cbSize := sizeof(TooltipInfo);
toolTipInfo.lpszText := pText;
SendMessage(tooltipHandle, TTM_GETTEXT, 0, LPARAM(@toolTipInfo));
Result := string(tooltipInfo.lpszText);

But I am not sure how this can get the text for all the buttons. Most
likely the TToolInfo structure needs to be initialized with some more
information - but I don't know how to do that - can anyone help me on
how to accomplish this? Thanks!

-Jatin

Rob Kennedy

unread,
Apr 20, 2008, 1:29:49 PM4/20/08
to
Jatin wrote:
> I have handle to a toolbar and I need to get the tooltip text of each of
> the tools buttons on it. I am attempting to get the tooltips using
> following way:
>
> tooltipHandle := SendMessage(hToolbarHandle, TB_GETTOOLTIPS, 0, 0);
>
> Above gets me the handle to the tooltips control for the toolbar. But
> beyond that I am clueless as to how to get the tooltip text for each of
> the tool buttons on this toolbar. I have Googled but haven't found
> anything except that I should send TTM_GETTEXT message to the tooltip
> control as follows:
>
> var
> tooltipHandle : tHandle;
> toolTipInfo : TToolInfo;
> pText : array[0..16000] of char;

The maximum length of a tool's text is 80 characters.

> toolTipInfo.cbSize := sizeof(TooltipInfo);
> toolTipInfo.lpszText := pText;
> SendMessage(tooltipHandle, TTM_GETTEXT, 0, LPARAM(@toolTipInfo));

That's telling the control to copy zero characters into the buffer.

> Result := string(tooltipInfo.lpszText);

The type-cast isn't required.

> But I am not sure how this can get the text for all the buttons.

It doesn't. You haven't set the hwnd and uId fields of the record like
the documentation tells you to. Those two fields identify which tool tip
you're fetching information about.

Even once you do that, it won't get the text for all the tool tips. It
only gets information for one. To get information about all of them,
you'll need to send a message for each tool tip separately. You'll
probably need to send a ttm_GetToolCount message. That won't give you
the value for the uId field, though. That gives you the number of tool
tips registered with tool-tip control. Get the uId field by sending a
ttm_EnumTools message for each tool tip.

In fact, since ttm_EnumTools fills the tip text, that would be a better
option than ttm_GetText is since it doesn't require you to know the tip
ID in advance.

> Most
> likely the TToolInfo structure needs to be initialized with some more
> information - but I don't know how to do that

How much of the documentation have you read so far?

> - can anyone help me on
> how to accomplish this? Thanks!


--
Rob

Jatin

unread,
Apr 21, 2008, 10:58:31 AM4/21/08
to

Rob Kennedy wrote:
> Jatin wrote:
>> I have handle to a toolbar and I need to get the tooltip text of each
>> of the tools buttons on it. I am attempting to get the tooltips using
>> following way:
>>
>> tooltipHandle := SendMessage(hToolbarHandle, TB_GETTOOLTIPS, 0, 0);
>>
>> Above gets me the handle to the tooltips control for the toolbar. But
>> beyond that I am clueless as to how to get the tooltip text for each
>> of the tool buttons on this toolbar. I have Googled but haven't found
>> anything except that I should send TTM_GETTEXT message to the tooltip
>> control as follows:
>>
>> var
>> tooltipHandle : tHandle;
>> toolTipInfo : TToolInfo;
>> pText : array[0..16000] of char;
>
> The maximum length of a tool's text is 80 characters.
>
>> toolTipInfo.cbSize := sizeof(TooltipInfo);
>> toolTipInfo.lpszText := pText;
>> SendMessage(tooltipHandle, TTM_GETTEXT, 0, LPARAM(@toolTipInfo));
>
> That's telling the control to copy zero characters into the buffer.

Why zero characters? If I had set up the uid and and hwnd of the tool
button (as you have pointed out below in your reply), it should get all
the characters in the tooltip of a particular tool button - at least
that's what the documentation on TTM_GETTEXT says.

>
>> Result := string(tooltipInfo.lpszText);
>
> The type-cast isn't required.
>
>> But I am not sure how this can get the text for all the buttons.
>
> It doesn't. You haven't set the hwnd and uId fields of the record like
> the documentation tells you to. Those two fields identify which tool tip
> you're fetching information about.
>
> Even once you do that, it won't get the text for all the tool tips. It
> only gets information for one. To get information about all of them,
> you'll need to send a message for each tool tip separately. You'll
> probably need to send a ttm_GetToolCount message. That won't give you
> the value for the uId field, though. That gives you the number of tool
> tips registered with tool-tip control. Get the uId field by sending a
> ttm_EnumTools message for each tool tip.
>
> In fact, since ttm_EnumTools fills the tip text, that would be a better
> option than ttm_GetText is since it doesn't require you to know the tip
> ID in advance.
>
>> Most likely the TToolInfo structure needs to be initialized with some
>> more information - but I don't know how to do that
>
> How much of the documentation have you read so far?

I did read the documentation on ToolbarWindow32 - there's no mention on
how to get the tool button's UID there. And I didn't expect to find that
information from the Tooltip control documentation. But as you have
pointed out, that's where it is - and I thank you for pointing that out
that.

-Jatin

Rob Kennedy

unread,
Apr 22, 2008, 4:41:09 AM4/22/08
to
Jatin wrote:
> Rob Kennedy wrote:
>> Jatin wrote:
>>> toolTipInfo.cbSize := sizeof(TooltipInfo);
>>> toolTipInfo.lpszText := pText;
>>> SendMessage(tooltipHandle, TTM_GETTEXT, 0, LPARAM(@toolTipInfo));
>>
>> That's telling the control to copy zero characters into the buffer.
>
> Why zero characters?

Because of the zero in that code.

> If I had set up the uid and and hwnd of the tool
> button (as you have pointed out below in your reply),

Not the window handle of the tool button; the window handle for the tool
with the given ID. For tool buttons' tips, that's probably the toolbar's
window handle.

> it should get all
> the characters in the tooltip of a particular tool button - at least
> that's what the documentation on TTM_GETTEXT says.

That's not what the documentation says.

Also, the documentation says nothing about buttons.

> I did read the documentation on ToolbarWindow32 - there's no mention on
> how to get the tool button's UID there. And I didn't expect to find that
> information from the Tooltip control documentation. But as you have
> pointed out, that's where it is - and I thank you for pointing that out
> that.

You're dealing with a tool-tip control in addition to a toolbar control.
You need to read about both. And if the tool-tip documentation says you
need a tool ID, then you need a tool ID, even if the toolbar doesn't
tell you about it. There's really no reason for the toolbar to mention
anything about tool-tip IDs; that's an implementation detail.

--
Rob

Jatin

unread,
Apr 22, 2008, 2:15:01 PM4/22/08
to
Rob Kennedy wrote:
> Jatin wrote:
>> Rob Kennedy wrote:
>>> Jatin wrote:
>>>> toolTipInfo.cbSize := sizeof(TooltipInfo);
>>>> toolTipInfo.lpszText := pText;
>>>> SendMessage(tooltipHandle, TTM_GETTEXT, 0, LPARAM(@toolTipInfo));
>>>
>>> That's telling the control to copy zero characters into the buffer.
>>
>> Why zero characters?
>
> Because of the zero in that code.
<snip>

Thanks, Rob.

-Jatin
===============

0 new messages