Solved

Is there anybody who can hunt Gozila?

Posted on 1999-01-12
3
294 Views
Last Modified: 2013-11-20
Hello Experts...

I'm developing some application of which interface looks like Exproler.
Main frame splitted into two panes, TreeView and ListView, and in ListView when mouse moves on item, it shows up some information about item using tooltip.
You may see this interface in "Address Book" of Microsoft's Outlook Express.
"Address Book" shows each item's property using tooltip in this way.

So I coded my application and it looks work well in first time.

BUT, in a few minute I found some Gozila grade bug in my code, and it still lives happyly.

Would you like to hear my history and how this Gozila born?

In first time, I spent a lot of days for making item's information tooltip in multi-line. It does not simple as I think first.
So I asked my problem this page. Some kind experts helps me how it can be made. He suggested that I can find answers about multiline tooltip in the MSJ archives titled 'Tiptoe through the tooltips' on Visual Studio 5/6 CD or at their website at www.microsoft.com/msj.

In that archive I'm surely find answers and I think all my problem solved at that time.
But it did not work correctly in some condition.
See some part of my code below.
---------------------------------------------------------
BOOL CItemListView::PreTranslateMessage(MSG* pMsg)
{
   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)
{
   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);
      }
      else
          pTTT->szText[0] = 0;

               
      bHandledNotify = TRUE;
  }
           
  return bHandledNotify;
}
---------------------------------------------------------
I declared some variables like this and handled properly.

CToolTip m_ToolTip;
CListCtrl* m_pList;

As it is a part of my whole code, but continuing explanation.

When ListView is active, Tooltip work correct but I change active view to TreeView and moves mouse on ListView item it still shows up Tooltip, but it has wrong contents. Tooltip works correctly only when LisView is active view.
And more, when Tooltip works correctly some problem exist too.
Another Tooltip window, has same contents not multi line but one line long, is blinking behind my application window.

I have tried to find what is wrong and trace my code in debugger then I found some information.

In debugging mode, I ran my application and changed current view to TreeView using mouse click, and I moves mouse pointer on ListView's item. At this point I checked tooltip text's contents then I noticed that tooltip text is not wrong.
OnToolTipNeedText() function works well and HitTest() function works well too.
But before showing tooltip, OnToolTipNeedText() function called again and tooltip text became wrong.
I think that wrong coordinate problem causes this and calls m_ToolTip.Activate(FALSE); in OnMouseMove() function. And it is problem under MFC framework when showing tooltip. so I don't know and what is the difference in showing tooltip in split window.
If the answer really exist under MFC framework. it is out of my ablity.
So you Experts only can solve this problem.

I'm afraid my English is not good for you to understand what I want to say. I think it is better way for you to understand what I really I want to tell you is tracing my buggy code in debugging mode.
If you want I'll send simple project has this problem.

Let's hunt for Gozila with 300pts.
0
Comment
Question by:leehdo
  • 2
3 Comments
 
LVL 3

Expert Comment

by:plaroche
ID: 1327553
Send your sample code at plaroche@cybectec.com, I'll take a look at it.
0
 

Author Comment

by:leehdo
ID: 1327554
Edited text of question
0
 
LVL 3

Accepted Solution

by:
plaroche earned 400 total points
ID: 1327555
ot the bug:

A TTN_NEEDTEXT is sent as a notification, as you may know notifications are sent via a WM_COMMAND message. These command messages in MFC are routed as followed:

active view
document
doc template
mainframe
app

(This is for a SDI app, the order might be wrong, don't have time to check)

The "Last Record" tooltip you're seeing comes from MFC's Prompts.rc file.  The toltip is set with this string in CFrameWnd::OnToolTipText() in MFC source code.

Why? Because your active view, CGroupTreeView does not handle TTN_NEEDTEXT, so the WM_COMMAND that is this notification continues its road until it is handled by the framewnd.  While at the same time you get mouse message in your right view and activate the tooltip. It then contains the wrong text.

Two solutions:

1) Handle TTN_NEEDTEXT notification in CMainFrame and pass it on to your CItemListView. If the view doesn't handle it call the base class: CFrameWnd::OnToolTipText

2) Handle TTN_NEEDTEXT in your left view (CGroupTreeView) and pass the notification to your right view by getting its pointer from the mainframe.

I prefer solution 1.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
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.
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…

758 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

21 Experts available now in Live!

Get 1:1 Help Now