Solved

A question for making multiline tooltip.

Posted on 1998-11-17
3
450 Views
Last Modified: 2013-11-20
Hello guys...

I'm wondering about making tooltip more than one line.

I simply try to make using new-line character '\n' like below .

  TOOLINFO ti;
  ti.lpszText = "First line.\nSecond line.\nThird line.";

But it did not working.

I've seen before Wab in Microsoft's Outlook Express shows listView item's property using multiline tooltip. How dose it implemented?

Sample program will be best answer.

Please let me know how to.

And I'm looking forward your kind answer.

P.S. Don't say simply I can find my answer at Codeguru.
0
Comment
Question by:Zeb
  • 2
3 Comments
 
LVL 7

Expert Comment

by:psdavis
ID: 1324876
Look for 'Tiptoe through the tooltips' in the MSJ archives either on your Visual C 5/6 CD or at their website at www.microsoft.com/msj.

There is suggestions about using the multiline tooltips there.

Phillip

p.s.  Hey, at least I didn't say codeguru...
0
 
LVL 7

Accepted Solution

by:
psdavis earned 200 total points
ID: 1324877
OK, I downloaded the sample code and it does show some stuff on DataTips.  It is from the April 97 issue.  The example DTDemo does indeed show multiline tooltips.

Some sample code...

void CDTDemoView::OnInitialUpdate()
{
      CView::OnInitialUpdate();

      CRect ClientRect(0, 0, 1000, 1000);
      if (m_ToolTip.Create(this, TTS_ALWAYSTIP) && m_ToolTip.AddTool(this))
      {
            m_ToolTip.SendMessage(TTM_SETMAXTIPWIDTH, 0, SHRT_MAX);
            m_ToolTip.SendMessage(TTM_SETDELAYTIME, TTDT_AUTOPOP, SHRT_MAX);
            m_ToolTip.SendMessage(TTM_SETDELAYTIME, TTDT_INITIAL, 200);
            m_ToolTip.SendMessage(TTM_SETDELAYTIME, TTDT_RESHOW, 200);
      }
      else
      {
            TRACE("Error in creating ToolTip");
      }
}

BOOL CDTDemoView::OnToolTipNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
{
      BOOL bHandledNotify = FALSE;

      CPoint CursorPos;
      VERIFY(::GetCursorPos(&CursorPos));
      ScreenToClient(&CursorPos);

      CRect ClientRect;
      GetClientRect(ClientRect);

      // Make certain that the cursor is in the client rect, because the
      // mainframe also wants these messages to provide tooltips for the
      // toolbar.
      if (ClientRect.PtInRect(CursorPos))
      {
            TOOLTIPTEXT *pTTT = (TOOLTIPTEXT *)pNMHDR;
            m_pCircleHit = HitTest(CursorPos);

            if (m_pCircleHit)
            {
                  // Adjust the text by filling in TOOLTIPTEXT
                  CString strTip;
                  const CPoint& Center = m_pCircleHit->GetCenter();
                  COLORREF Color = m_pCircleHit->GetColor();
                  strTip.Format("Center:  (%d, %d)\nRadius:  %d\nColor:  (%d, %d, %d)",
                        Center.x, Center.y, m_pCircleHit->GetRadius(),
                        (int)GetRValue(Color), (int)GetGValue(Color), (int)GetBValue(Color));
                  ASSERT(strTip.GetLength() < sizeof(pTTT->szText));
                  ::strcpy(pTTT->szText, strTip);

                  // Set the text color to same color as circle
                  m_ToolTip.SendMessage(TTM_SETTIPTEXTCOLOR, Color, 0L);
            }
            else
            {
                  pTTT->szText[0] = 0;
            }
            bHandledNotify = TRUE;
      }
      return bHandledNotify;
}


Good luck

Phillip
0
 

Author Comment

by:Zeb
ID: 1324878
Thank you Phillip.

I'm sorry for late grading your answer.

I can find what I need in MSJ April 97 about datatip as you proposed.

But I still have some problem.

My application has split window with TreeView and ListView like Window Explorer.
and I used tooltip(Datatip) to show item property in ListView.
When ListView is active datatip work correct but I change active view to TreeView and moves mouse on ListView item it still shows up Tooltip Text with garbage contents.

Can I show Datatip only when ListView is active?

I made this like below.

BOOL CItemListView::PreTranslateMessage(MSG* pMsg)
{
      // TODO: Add your specialized code here and/or call the base class
    if(::IsWindow(m_ToolTip.m_hWnd) && pMsg->hwnd == m_hWnd)
    {
        switch(pMsg->message)
        {
                  case WM_LBUTTONDOWN:    
                  case WM_MOUSEMOVE:
                  case WM_LBUTTONUP:    
                  case WM_RBUTTONDOWN:
                  case WM_MBUTTONDOWN:    
                  case WM_RBUTTONUP:
                  case WM_MBUTTONUP:
                        m_ToolTip.RelayEvent(pMsg);
                        break;
            }
    }      

      return CListView::PreTranslateMessage(pMsg);
}

void CItemListView::OnMouseMove(UINT nFlags, CPoint point)
{
      // TODO: Add your message handler code here and/or call default
//      m_pList->ScreenToClient(&ptList);
      const int nItemHit = m_pList->HitTest(point);

      if(nItemHit > -1)
    {
        if(nItemHit < 0 || nItemHit != m_nItemIndexHit)
        {
            // Use Activate() to hide the tooltip.
            m_ToolTip.Activate(FALSE);
            }

            if(nItemHit > -1)
            {
            m_ToolTip.Activate(TRUE);
            m_nItemIndexHit = nItemHit;
            }

      }

      CListView::OnMouseMove(nFlags, point);
}

BOOL CItemListView::OnToolTipNeedText(UINT id, NMHDR * pNMHDR, LRESULT * pResult)
{
    BOOL bHandledNotify = FALSE;
    CPoint CursorPos;
      VERIFY(::GetCursorPos(&CursorPos));
    m_pList->ScreenToClient(&CursorPos);

    CRect ClientRect;
    m_pList->GetClientRect(&ClientRect);
   
      // Make certain that the cursor is in the client rect, because the
    // mainframe also wants these messages to provide tooltips for the
    // toolbar.
    if(ClientRect.PtInRect(CursorPos))
    {
            TOOLTIPTEXT *pTTT = (TOOLTIPTEXT*)pNMHDR;
            m_nItemIndexHit = m_pList->HitTest(CursorPos);

            if(m_nItemIndexHit > -1)
            {
                  // Adjust the text by filling in TOOLTIPTEXT
                  CString strTip;
                  strTip.Format("Item Num : %d\nSecond Line", m_nItemIndexHit);

                  ASSERT(strTip.GetLength() < sizeof(pTTT->szText));
                  ::strcpy(pTTT->szText, strTip);
           
                  // Set the text color to same color as circle
                  m_ToolTip.SendMessage(TTM_SETTIPTEXTCOLOR, RGB(0,0,0), 0L);
        }
        else
        {
            pTTT->szText[0] = 0;
        }
       
            bHandledNotify = TRUE;
    }
   
      return bHandledNotify;
}


If you don't mind I'll send my source code to you.
Tell me how foolish I have done.

And it seems Tooltip text must be less than 80.

      ASSERT(strTip.GetLength() < sizeof(pTTT->szText));

Is it impossible Tooltip text more than 80 characters?


Thank you again.
                           Zeb Lee
e-mail : zeb@unitel.co.kr
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now