Question : Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.

Wxp Pro SP1 VC++6.0 SP5

I have a dialog based app in which i display tooltips for various controls. Basics are done by the app wizard (activation, PreTranslateMessage, ... ?) and in the OnInitDialog I add the tooltips successfully using two methods:

AddTool (GetDlgItem (IDC_THIS), IDC_THIS); // control ID and string resource ID are identical numbers.
or for static controls
AddTool (this, csText, cr, IDC_THIS); // csText is a CString with the tooltip text and cr the CRect of the static control.

To allow changing tooltips for buttons which can be disabled as well I tried to add a third method:

AddTool (this); // or AddTool (this, LPSTR_TEXTCALLBACK, cr, IDC_THIS)
and added a handler for TTN_NEEDTEXT message. But this handler is never called. Why? Do I either need to supply text for all controls in this handler or supply the text in the AddTool call for all controls?

Answer : Mixed tooltips using AddTool (GetDlgItem (IDC_THIS), IDC_THIS) and AddTool (this, LPSTR_TEXTCALLBACK) how to.

I have this

in OnInitDialog

            // Create the ToolTip control.
            m_tooltip.Create(this, TTS_NOPREFIX);
            m_tooltip.SetMaxTipWidth(600);      //allow it to be very wide
            m_tooltip.SetDelayTime(TTDT_AUTOPOP, 10000);      //display for 10 seconds (stop flashing)
            m_tooltip.Activate(TRUE);

            m_tooltip.AddTool(GetDlgItem(IDC_LIST1), LPSTR_TEXTCALLBACK);

and in PreTranslateMEssage
      {
            // Let the ToolTip process this message.
            m_tooltip.RelayEvent(pMsg);
      }
    if(pMsg->message == WM_MOUSEMOVE)
      {
            m_tooltip.Update();   //different text for different locations on the control
      }

and this to fill the tip
message map
      ON_NOTIFY_EX( TTN_NEEDTEXT, 0, OnToolTipNotify )

function
BOOL CSortDlg::OnToolTipNotify( UINT id, NMHDR * pNMHDR, LRESULT * pResult )
{
    TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
    UINT nID =pNMHDR->idFrom;
      static TCHAR szMessage[256];
      static CPoint point;
      static UINT nIndex;
      static BOOL bOutside;

    if (pTTT->uFlags & TTF_IDISHWND)
    {
            if(::GetDlgCtrlID((HWND)nID) == IDC_LIST1)
            {
                  //We are on the list - are we on a line of text?
                  VERIFY(GetCursorPos(&point));
                  m_lstSort.ScreenToClient(&point);
                  nIndex = m_lstSort.ItemFromPoint(point, bOutside);

                  if(!bOutside)
                  {
                        m_lstSort.GetText(nIndex, szMessage);

                        pTTT->lpszText = szMessage;
                        return true;
                  }
            }
    }
    return false;
}
Random Solutions  
 
programming4us programming4us