ComboBox and ToolTips 
Author Message
 ComboBox and ToolTips

Hi all.

I'm trying to add tooltips to both the edit control and the listbox of a
dropdown combobox of a dialog app. So far, the only thing Ive accomplished
is subclassing the combo box, calling enable tooltips, overriding
OnToolHitTest and handling the TTF_NEEDTEXT notification. This works if I'm
only displaying a tooltip for the edit control, but it only works before the
contents of the combobox change. If they do for any reason (opening the
combobox, changing text in edit control or calling CComboBox::AddString()),
the tooltips stop working.

I'm also looking into adding tooltips for strings that do not fit into the
listbox of the combobox, Any Ideas about this?

I need some ideas and pointers that can get me started and on the right path
to figuring this out for myself. Thanks for any help you can give me.

--
Tomas Restrepo

Ultimately, all things are known
because you want to believe you know



Tue, 01 Aug 2000 03:00:00 GMT  
 ComboBox and ToolTips

Quote:
>This works if I'm
>only displaying a tooltip for the edit control, but it only works before the
>contents of the combobox change. If they do for any reason (opening the
>combobox, changing text in edit control or calling CComboBox::AddString()),
>the tooltips stop working.

Tomas,

I get the same problem too. There are some weird quirks with tooltips
for dialog controls. I find that the documentation doesn't really tell
me enough about the implementation in order to understand things well
enough to make anything other than guesses to fix the problems.

Try this too - move the mouse over the combo box drop down arrow to
show the combo box tooltip, then move the mouse over the combo box's
edit control without moving it over the dialog box. Does the tooltip
now flicker on and off repeatedly for you? The tooltip also flickers
for me on every alternate click/release of the mouse button in the
combo box's edit field.

I should add that I don't see the same problem with an equivalent SDK
implementation - with that the combo box's edit field tooltip works
consistently. There's definitely something strange with the MFC
implementation of tooltips for dialog controls.

I suggest that you create a really small simple application that
illustrates the situation and let MS know via the reporting tool on
the MS web site (somewhere). I'm also working on an example to
illustrate these issues too.

I'm still experimenting but I've just tried this and it remedies
things in my situation:

BOOL CMfcDlgttDlg::PreTranslateMessage(MSG* pMsg)
{
        /* Code I've transplanted from _AfxRelayToolTipMessage (just a
guess as my SDK project is OK) */
        MSG msg = *pMsg;
        msg.hwnd = (HWND)m_tooltip.SendMessage(TTM_WINDOWFROMPOINT, 0,
(LPARAM)&msg.pt);
        CPoint pt = pMsg->pt;
        if (msg.message >= WM_MOUSEFIRST && msg.message <=
WM_MOUSELAST)
                ::ScreenToClient(msg.hwnd, &pt);
        msg.lParam = MAKELONG(pt.x, pt.y);

        // relay mouse event before deleting old tool
        m_tooltip.SendMessage(TTM_RELAYEVENT, 0, (LPARAM)&msg);

        // CG: The following block was added by the ToolTips
component.
        {
                // Let the ToolTip process this message.
//              m_tooltip.RelayEvent(pMsg);
        }
        return CDialog::PreTranslateMessage(pMsg);      // CG: This
was added by the ToolTips component.

Quote:
}
>I'm also looking into adding tooltips for strings that do not fit into the
>listbox of the combobox, Any Ideas about this?

I guess you'll need to derive your own listbox class and handle the
mouse move messages. There's an article on some aspects of tooltips in
MSJ April 1997, one it does cover is providing data tips which sounds
something like what you want.

Dave
----
Address is altered to discourage junk mail.
Remove ".---" for the real address.



Thu, 03 Aug 2000 03:00:00 GMT  
 ComboBox and ToolTips

Hi David.

Thanks for your response. FYI the code I'm using now (after changing a
couple of things) seems to work pretty well, though there might be a better
way.

After calling EnableToolTips(), I override OnToolHitTest() and provide a
handler for TTF+AF8-NEEDTEXT which look like this:

int CSubComboBox::OnToolHitTest( CPoint point, TOOLINFO+ACo- pTI ) const
+AHs-
 ASSERT+AF8-VALID(this)+ADs-
 ASSERT(::IsWindow(m+AF8-hWnd))+ADs-
 CWnd+ACo- pEditWnd +AD0- GetWindow(GW+AF8-CHILD)+ADs-

 CRect rc+ADs- pEditWnd-+AD4-GetClientRect(rc)+ADs-
 pTI-+AD4-hwnd +AD0- m+AF8-hWnd+ADs-
 pTI-+AD4-uFlags +AHwAPQ- TTF+AF8-CENTERTIP +AHw- TTF+AF8-SUBCLASS+ADs-

 if (rc.PtInRect(point))
 +AHs-
  pTI-+AD4-uId  +AD0- SCB+AF8-EDITHANDLE+ADs-
  pTI-+AD4-lpszText +AD0- LPSTR+AF8-TEXTCALLBACK+ADs-
  pTI-+AD4-rect +AD0- rc+ADs-
  return 1+ADs-
 +AH0-
 return 0+ADs-
+AH0-

BOOL CSubComboBox::OnToolNeedText(UINT id, NMHDR +ACo- pTTTStruct, LRESULT +ACo-
pResult)
+AHs-
 TOOLTIPTEXT+ACo- pTTT +AD0- (TOOLTIPTEXT+ACo-)pTTTStruct+ADs-
 UINT uID +AD0- pTTTStruct-+AD4-idFrom+ADs-
 CString st+ADs-
 CDC+ACo- dc +AD0- GetDC()+ADs-
 CRect rc+ADs-

 if(uID +AD0APQ- SCB+AF8-EDITHANDLE)
 +AHs-
  GetWindowText(st)+ADs-
  CSize size +AD0- dc-+AD4-GetTextExtent(st)+ADs-
  GetClientRect(rc)+ADs-
  if(size.cx +AD4- rc.Width()) +AHs-
   lstrcpy(pTTT-+AD4-lpszText, st)+ADs-
   return TRUE+ADs-
  +AH0-
  return FALSE+ADs-
+AH0-

By doing this, I provide tooltips only for the Edit control, so the tooltip
doesn't appear when the mouse is over the dropbox. Aside from that, it only
displays the tooltip if the text in the edit box is too long to fit in
it(there must be a better way of doing it, though).

See if it might work for you and tell me.
--
Tomas Restrepo
winder+AEA-bigfoot.com
Ultimately, all things are known
because you want to believe you know

+AD4APg-This works if I'm
+AD4APg-only displaying a tooltip for the edit control, but it only works before
the
+AD4APg-contents of the combobox change. If they do for any reason (opening the
+AD4APg-combobox, changing text in edit control or calling
CComboBox::AddString()),
+AD4APg-the tooltips stop working.
+AD4-
+AD4-Tomas,
+AD4-
+AD4-I get the same problem too. There are some weird quirks with tooltips
+AD4-for dialog controls. I find that the documentation doesn't really tell
+AD4-me enough about the implementation in order to understand things well
+AD4-enough to make anything other than guesses to fix the problems.
+AD4-
+AD4-Try this too - move the mouse over the combo box drop down arrow to
+AD4-show the combo box tooltip, then move the mouse over the combo box's
+AD4-edit control without moving it over the dialog box. Does the tooltip
+AD4-now flicker on and off repeatedly for you? The tooltip also flickers
+AD4-for me on every alternate click/release of the mouse button in the
+AD4-combo box's edit field.
+AD4-
+AD4-I should add that I don't see the same problem with an equivalent SDK
+AD4-implementation - with that the combo box's edit field tooltip works
+AD4-consistently. There's definitely something strange with the MFC
+AD4-implementation of tooltips for dialog controls.
+AD4-
+AD4-I suggest that you create a really small simple application that
+AD4-illustrates the situation and let MS know via the reporting tool on
+AD4-the MS web site (somewhere). I'm also working on an example to
+AD4-illustrate these issues too.
+AD4-
+AD4-I'm still experimenting but I've just tried this and it remedies
+AD4-things in my situation:
+AD4-
+AD4-BOOL CMfcDlgttDlg::PreTranslateMessage(MSG+ACo- pMsg)
+AD4Aew-
+AD4- /+ACo- Code I've transplanted from +AF8-AfxRelayToolTipMessage (just a
+AD4-guess as my SDK project is OK) +ACo-/
+AD4- MSG msg +AD0- +ACo-pMsg+ADs-
+AD4- msg.hwnd +AD0- (HWND)m+AF8-tooltip.SendMessage(TTM+AF8-WINDOWFROMPOINT, 0,
+AD4-(LPARAM)+ACY-msg.pt)+ADs-
+AD4- CPoint pt +AD0- pMsg-+AD4-pt+ADs-
+AD4- if (msg.message +AD4APQ- WM+AF8-MOUSEFIRST +ACYAJg- msg.message +ADwAPQ-
+AD4-WM+AF8-MOUSELAST)
+AD4- ::ScreenToClient(msg.hwnd, +ACY-pt)+ADs-
+AD4- msg.lParam +AD0- MAKELONG(pt.x, pt.y)+ADs-
+AD4-
+AD4- // relay mouse event before deleting old tool
+AD4- m+AF8-tooltip.SendMessage(TTM+AF8-RELAYEVENT, 0, (LPARAM)+ACY-msg)+ADs-
+AD4-
+AD4- // CG: The following block was added by the ToolTips
+AD4-component.
+AD4- +AHs-
+AD4- // Let the ToolTip process this message.
+AD4-// m+AF8-tooltip.RelayEvent(pMsg)+ADs-
+AD4- +AH0-
+AD4- return CDialog::PreTranslateMessage(pMsg)+ADs- // CG: This
+AD4-was added by the ToolTips component.
+AD4AfQ-
+AD4-
+AD4APg-I'm also looking into adding tooltips for strings that do not fit into the
+AD4APg-listbox of the combobox, Any Ideas about this?
+AD4-
+AD4-I guess you'll need to derive your own listbox class and handle the
+AD4-mouse move messages. There's an article on some aspects of tooltips in
+AD4-MSJ April 1997, one it does cover is providing data tips which sounds
+AD4-something like what you want.
+AD4-
+AD4-Dave
+AD4-----
+AD4-Address is altered to discourage junk mail.
+AD4-Remove +ACI-.---+ACI- for the real address.



Fri, 04 Aug 2000 03:00:00 GMT  
 ComboBox and ToolTips

Tomas,

Can you re-post in a different format - the text I see is littered
with formatting characters that make your code unreadable.

Dave

Quote:
>int CSubComboBox::OnToolHitTest( CPoint point, TOOLINFO+ACo- pTI ) const
>+AHs-
> ASSERT+AF8-VALID(this)+ADs-
> ASSERT(::IsWindow(m+AF8-hWnd))+ADs-
> ...

----
Address is altered to discourage junk mail.
Remove ".---" for the real address.


Sat, 05 Aug 2000 03:00:00 GMT  
 ComboBox and ToolTips

OK, here it goes. Read my comments above for an explanation

int CSubComboBox::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
{
    ASSERT_VALID(this);
    ASSERT(::IsWindow(m_hWnd));
    CWnd* pEditWnd = GetWindow(GW_CHILD);

    CRect rc; pEditWnd->GetClientRect(rc);
    pTI->hwnd = m_hWnd;
    pTI->uFlags |= TTF_CENTERTIP | TTF_SUBCLASS;

    if (rc.PtInRect(point))
    {
      pTI->uId  = SCB_EDITHANDLE;
      pTI->lpszText = LPSTR_TEXTCALLBACK;
      pTI->rect = rc;
      return 1;
    }
    return 0;

Quote:
}

BOOL CSubComboBox::OnToolNeedText(UINT id, NMHDR * pTTTStruct,
        LRESULT * pResult)
{
    TOOLTIPTEXT* pTTT = (TOOLTIPTEXT*)pTTTStruct;
    UINT uID = pTTTStruct->idFrom;
    CString st;
    CDC* dc = GetDC();
    CRect rc;

    if(uID == SCB_EDITHANDLE || uID == 1)
    {
          GetWindowText(st);
          CSize size = dc->GetTextExtent(st);
          GetClientRect(rc);
          if(size.cx > rc.Width()) {
               lstrcpy(pTTT->lpszText, st);
               return TRUE;
         }
    }

    return FALSE;

Quote:
}

--
Tomas Restrepo

Ultimately, all things are known
because you want to believe you know
Quote:

>Tomas,

>Can you re-post in a different format - the text I see is littered
>with formatting characters that make your code unreadable.

>Dave

>>int CSubComboBox::OnToolHitTest( CPoint point, TOOLINFO* pTI ) const
>>{
>> ASSERT_VALID(this);
>> ASSERT(::IsWindow(m_hWnd));
>> ...

>----
>Address is altered to discourage junk mail.
>Remove ".---" for the real address.



Sat, 05 Aug 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. ToolTips on ComboBox DropDown List

2. VS.net IDE types ComboBox and Members ComboBox

3. Pen Style Combobox and OwnerDraw Combobox

4. ComboBox and ComboBox.ObjectCollection usage

5. Slider Tooltips

6. Balloon ToolTips

7. Problem with ToolTips and Group Box Controls

8. Tooltips

9. Tooltips in converted Vcp6 code

10. Loss of tooltips

11. tooltips

12. VC++ 7.0 or Visual Studio .NET problem in displaying tooltips

 

 
Powered by phpBB® Forum Software