get text from a tooltip window

get text from a tooltip window

Post by Stephen Ken » Thu, 21 Nov 2002 22:12:07



To get the ToolTip's text you must know the id of the tool you want the text
from.  GetDlgCtrlID does not return the Tool id.  So to get the ids of all
the tools that the ToolTip control contains you will need to enumerate the
tools using TTM_GETTOOLCOUNT and TTM_ENUMTOOLS.  Remember that a single
ToolTip control can host several ToolTips (tools).

If you are trying to encapsulate this in a function then your function will
need to return an array (or similar structure) of strings.

If you only need to know the text as it's shown or after the ToolTip pops
(hidden) then you can get the Tool Id from the TTN_SHOW or TTN_POP messages
respectfully.  Or if you want information only about the current tool you
can use TTM_GETCURRENTTOOL.

Stephen Kent


Quote:> I need to get the text from any ToolTip Window given his
> HWND. My code at this moment looks like this.

>     TOOLINFO ToolInfo;
>     ToolInfo.cbSize = sizeof(TOOLINFO);
>     ToolInfo.uFlags = 0;
>     ToolInfo.uId = ::GetDlgCtrlID(ToolTip);
>     ToolInfo.hwnd = GetParent(ToolTip);
>     ToolInfo.lpszText = new char[1024];
>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
> GWL_HINSTANCE);

>     SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
> &ToolInfo);

> But this does not work, if anyone have any idea please
> help me :)

> Thanks in advance

 
 
 

get text from a tooltip window

Post by Isaac Lascasa » Fri, 22 Nov 2002 04:24:50


Thanks Stephen Kent, now my code looks like this, but it
appears as after enumerating the tools they are empty. I
call this function to all the windows with TOOLTIP class
i found enumerating all the windows. The ToolInfo
structure did not get fillet after TTM_ENUMTOOLS :(

string GetTooltipText(HWND ToolTip)
    {
    TOOLINFO ToolInfo;
    ToolInfo.uFlags = 0;
    ToolInfo.uId = 0;
    ToolInfo.hwnd = GetParent(ToolTip);
    ToolInfo.lpszText = new char[1024];
    ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
GWL_HINSTANCE);
    ToolInfo.cbSize = sizeof(TOOLINFO);

    UINT count = SendMessage(ToolTip, TTM_GETTOOLCOUNT,
0, 0);
    sprint("I have %d items.", count);

    for (UINT i = 0; i < count; i++)
        {
        if (SendMessage(ToolTip, TTM_ENUMTOOLS, (WPARAM)
(UINT)i, (LPARAM)(LPTOOLINFO)&ToolInfo) == TRUE)
            {
            // I supone at this point Toolinfo.uId has
correct value
            // but ToolInfo remains as before calling
TTM_ENUMTOOLS
            SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
&ToolInfo);
            sprint(ToolInfo.lpszText);
            return string(ToolInfo.lpszText);
            }
        else
            {
            sprint("DID NOT WORK");
            return string("");
            }
        }

    return string("");
    }

Isaac Lascasas

Quote:>-----Original Message-----
>To get the ToolTip's text you must know the id of the

tool you want the text
Quote:>from.  GetDlgCtrlID does not return the Tool id.  So to
get the ids of all
>the tools that the ToolTip control contains you will

need to enumerate the
Quote:>tools using TTM_GETTOOLCOUNT and TTM_ENUMTOOLS.  

Remember that a single
>ToolTip control can host several ToolTips (tools).

>If you are trying to encapsulate this in a function then
your function will
>need to return an array (or similar structure) of
strings.

>If you only need to know the text as it's shown or after
the ToolTip pops
>(hidden) then you can get the Tool Id from the TTN_SHOW
or TTN_POP messages
>respectfully.  Or if you want information only about the
current tool you
>can use TTM_GETCURRENTTOOL.

>Stephen Kent



>> I need to get the text from any ToolTip Window given
his
>> HWND. My code at this moment looks like this.

>>     TOOLINFO ToolInfo;
>>     ToolInfo.cbSize = sizeof(TOOLINFO);
>>     ToolInfo.uFlags = 0;
>>     ToolInfo.uId = ::GetDlgCtrlID(ToolTip);
>>     ToolInfo.hwnd = GetParent(ToolTip);
>>     ToolInfo.lpszText = new char[1024];
>>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
>> GWL_HINSTANCE);

>>     SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
>> &ToolInfo);

>> But this does not work, if anyone have any idea please
>> help me :)

>> Thanks in advance

>.


 
 
 

get text from a tooltip window

Post by Stephen Ken » Fri, 22 Nov 2002 04:40:26


The extra cast to LPTOOLINFO in the TTM_ENUMTOOLS message is unnecessary as
for the TOOLINFO structure not being filled I'll have to try this once I get
home.  So hopefully I should have a follow-up for you within the next couple
of hours.

Stephen Kent


> Thanks Stephen Kent, now my code looks like this, but it
> appears as after enumerating the tools they are empty. I
> call this function to all the windows with TOOLTIP class
> i found enumerating all the windows. The ToolInfo
> structure did not get fillet after TTM_ENUMTOOLS :(

> string GetTooltipText(HWND ToolTip)
>     {
>     TOOLINFO ToolInfo;
>     ToolInfo.uFlags = 0;
>     ToolInfo.uId = 0;
>     ToolInfo.hwnd = GetParent(ToolTip);
>     ToolInfo.lpszText = new char[1024];
>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
> GWL_HINSTANCE);
>     ToolInfo.cbSize = sizeof(TOOLINFO);

>     UINT count = SendMessage(ToolTip, TTM_GETTOOLCOUNT,
> 0, 0);
>     sprint("I have %d items.", count);

>     for (UINT i = 0; i < count; i++)
>         {
>         if (SendMessage(ToolTip, TTM_ENUMTOOLS, (WPARAM)
> (UINT)i, (LPARAM)(LPTOOLINFO)&ToolInfo) == TRUE)
>             {
>             // I supone at this point Toolinfo.uId has
> correct value
>             // but ToolInfo remains as before calling
> TTM_ENUMTOOLS
>             SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
> &ToolInfo);
>             sprint(ToolInfo.lpszText);
>             return string(ToolInfo.lpszText);
>             }
>         else
>             {
>             sprint("DID NOT WORK");
>             return string("");
>             }
>         }

>     return string("");
>     }

> Isaac Lascasas

> >-----Original Message-----
> >To get the ToolTip's text you must know the id of the
> tool you want the text
> >from.  GetDlgCtrlID does not return the Tool id.  So to
> get the ids of all
> >the tools that the ToolTip control contains you will
> need to enumerate the
> >tools using TTM_GETTOOLCOUNT and TTM_ENUMTOOLS.
> Remember that a single
> >ToolTip control can host several ToolTips (tools).

> >If you are trying to encapsulate this in a function then
> your function will
> >need to return an array (or similar structure) of
> strings.

> >If you only need to know the text as it's shown or after
> the ToolTip pops
> >(hidden) then you can get the Tool Id from the TTN_SHOW
> or TTN_POP messages
> >respectfully.  Or if you want information only about the
> current tool you
> >can use TTM_GETCURRENTTOOL.

> >Stephen Kent



> >> I need to get the text from any ToolTip Window given
> his
> >> HWND. My code at this moment looks like this.

> >>     TOOLINFO ToolInfo;
> >>     ToolInfo.cbSize = sizeof(TOOLINFO);
> >>     ToolInfo.uFlags = 0;
> >>     ToolInfo.uId = ::GetDlgCtrlID(ToolTip);
> >>     ToolInfo.hwnd = GetParent(ToolTip);
> >>     ToolInfo.lpszText = new char[1024];
> >>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
> >> GWL_HINSTANCE);

> >>     SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
> >> &ToolInfo);

> >> But this does not work, if anyone have any idea please
> >> help me :)

> >> Thanks in advance

> >.

 
 
 

get text from a tooltip window

Post by Stephen Ken » Fri, 22 Nov 2002 07:07:41


The following works for me.  The TTM_GETTEXT call was redundant as the
TTM_ENUMTOOLS message filled the text buffer for me.  I changed the code
somewhat to be more ANSI/UNICODE friendly and pass the string back using an
automation compatible type.  I had simply thrown the code into an existing
ActiveX control I had so as not to re-write the create ToolTip code.

STDMETHODIMP CCoolCommand::ReturnToolTipText(long lToolTip, BSTR
*pbstrToolTipText)
{
 HRESULT hr = S_FALSE;
 CComBSTR bstrText = _T("");
 HWND hWndToolTip = (HWND)lToolTip;
 TOOLINFO tiToolInfo;
 tiToolInfo.uFlags = 0;
 tiToolInfo.uId = 0;
 tiToolInfo.hwnd = ::GetParent(hWndToolTip);
 tiToolInfo.lpszText = new TCHAR[1024];
 tiToolInfo.hinst = (HINSTANCE)::GetWindowLong(hWndToolTip, GWL_HINSTANCE);
 tiToolInfo.cbSize = sizeof(TOOLINFO);

 UINT count = SendMessage(hWndToolTip, TTM_GETTOOLCOUNT, 0, 0);

 for (UINT i = 0; i < count; i++)
 {
  if (SendMessage(hWndToolTip, TTM_ENUMTOOLS, (WPARAM)i,
(LPARAM)&tiToolInfo) == TRUE)
  {
   bstrText = tiToolInfo.lpszText;
   hr = S_OK;
   break;
  }
 }

 delete [] tiToolInfo.lpszText;

 *pbstrToolTipText = bstrText.Detach();

 return hr;

Quote:}

Stephen Kent


> Thanks Stephen Kent, now my code looks like this, but it
> appears as after enumerating the tools they are empty. I
> call this function to all the windows with TOOLTIP class
> i found enumerating all the windows. The ToolInfo
> structure did not get fillet after TTM_ENUMTOOLS :(

> string GetTooltipText(HWND ToolTip)
>     {
>     TOOLINFO ToolInfo;
>     ToolInfo.uFlags = 0;
>     ToolInfo.uId = 0;
>     ToolInfo.hwnd = GetParent(ToolTip);
>     ToolInfo.lpszText = new char[1024];
>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
> GWL_HINSTANCE);
>     ToolInfo.cbSize = sizeof(TOOLINFO);

>     UINT count = SendMessage(ToolTip, TTM_GETTOOLCOUNT,
> 0, 0);
>     sprint("I have %d items.", count);

>     for (UINT i = 0; i < count; i++)
>         {
>         if (SendMessage(ToolTip, TTM_ENUMTOOLS, (WPARAM)
> (UINT)i, (LPARAM)(LPTOOLINFO)&ToolInfo) == TRUE)
>             {
>             // I supone at this point Toolinfo.uId has
> correct value
>             // but ToolInfo remains as before calling
> TTM_ENUMTOOLS
>             SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
> &ToolInfo);
>             sprint(ToolInfo.lpszText);
>             return string(ToolInfo.lpszText);
>             }
>         else
>             {
>             sprint("DID NOT WORK");
>             return string("");
>             }
>         }

>     return string("");
>     }

> Isaac Lascasas

> >-----Original Message-----
> >To get the ToolTip's text you must know the id of the
> tool you want the text
> >from.  GetDlgCtrlID does not return the Tool id.  So to
> get the ids of all
> >the tools that the ToolTip control contains you will
> need to enumerate the
> >tools using TTM_GETTOOLCOUNT and TTM_ENUMTOOLS.
> Remember that a single
> >ToolTip control can host several ToolTips (tools).

> >If you are trying to encapsulate this in a function then
> your function will
> >need to return an array (or similar structure) of
> strings.

> >If you only need to know the text as it's shown or after
> the ToolTip pops
> >(hidden) then you can get the Tool Id from the TTN_SHOW
> or TTN_POP messages
> >respectfully.  Or if you want information only about the
> current tool you
> >can use TTM_GETCURRENTTOOL.

> >Stephen Kent



> >> I need to get the text from any ToolTip Window given
> his
> >> HWND. My code at this moment looks like this.

> >>     TOOLINFO ToolInfo;
> >>     ToolInfo.cbSize = sizeof(TOOLINFO);
> >>     ToolInfo.uFlags = 0;
> >>     ToolInfo.uId = ::GetDlgCtrlID(ToolTip);
> >>     ToolInfo.hwnd = GetParent(ToolTip);
> >>     ToolInfo.lpszText = new char[1024];
> >>     ToolInfo.hinst = (HINSTANCE) GetWindowLong(ToolTip,
> >> GWL_HINSTANCE);

> >>     SendMessage(ToolTip, TTM_GETTEXT, 0, (LPARAM)
> >> &ToolInfo);

> >> But this does not work, if anyone have any idea please
> >> help me :)

> >> Thanks in advance

> >.

 
 
 

1. Help getting tooltip text

How do i get the tooltip text specified in the menu resource for a
specific menu item? I want to display the tooltip text in a menu
customization dialog. The text should be displayed permanently, that
is, I do not want to just move the tooltip area.

How do I do? Please reply by email as I'm on a borrowed news account.

Jonas Lindskog

--
-----------------------------------------------------
John Hind                      | Ph:  +46 8 580 85102

Snail-mail: CelsiusTech, S-175 88, Jarfalla, Sweden
-----------------------------------------------------

2. installing WMP 7.1 and *really* preventing the reboot

3. tooltip-type window over edit box text?

4. Anybody actually use Netscape 4.7?

5. Text in FAX text box gets cut off when printing

6. Win2k 's Help file

7. Help for getting texts from several string text widgets of Xaw.

8. tweakUI power tools and system tray

9. How do I kill the tooltips/balloons/text labels??

10. String resource format for dialog toolbar button & tooltip text

11. Is it possible to set the text of a tooltip at run-time?

12. CSliderCtrl tooltip text modification

13. Tooltip text font