Solved

A question for making multiline tooltip.

Posted on 1998-11-17
3
454 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 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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
lucky13 challenge 11 164
changeXy challenge 13 96
ASP.NET C# MessageBox.Show Showing a modal dialog box or form when the application ... 2 196
Problem to Office 1 66
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: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.

737 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