[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

A question for making multiline tooltip.

Posted on 1998-11-17
3
Medium Priority
?
464 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 600 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

650 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