Solved

A question for making multiline tooltip.

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
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 video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

759 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

20 Experts available now in Live!

Get 1:1 Help Now