Microsoft KB Archive/172276: Difference between revisions

From BetaArchive Wiki
m (Text replacement - ">" to ">")
m (Text replacement - "&" to "&")
 
(One intermediate revision by the same user not shown)
Line 86: Line 86:
Here is a sample OnToolHitTest() that implements the workaround:
Here is a sample OnToolHitTest() that implements the workaround:
<pre class="codesample">  #include <WTYPES.H>
<pre class="codesample">  #include <WTYPES.H>
   #include &quot;..\src\afximpl.h&quot;
   #include "..\src\afximpl.h"


   int CSuperTipFormView::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
   int CSuperTipFormView::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
Line 95: Line 95:
       // (don't use WindowFromPoint, because it ignores disabled windows)
       // (don't use WindowFromPoint, because it ignores disabled windows)
       // see _AfxChildWindowFromPoint(m_hWnd, point);
       // see _AfxChildWindowFromPoint(m_hWnd, point);
       ::ClientToScreen(m_hWnd, &amp;point);
       ::ClientToScreen(m_hWnd, &point);
       HWND hChild = ::GetWindow(m_hWnd, GW_CHILD);
       HWND hChild = ::GetWindow(m_hWnd, GW_CHILD);
       for (; hChild != NULL; hChild = ::GetWindow(hChild, GW_HWNDNEXT))
       for (; hChild != NULL; hChild = ::GetWindow(hChild, GW_HWNDNEXT))
       {
       {
         if (_AfxGetDlgCtrlID(hChild) != (WORD)-1 &amp;&amp;
         if (_AfxGetDlgCtrlID(hChild) != (WORD)-1 &&
               (::GetWindowLong(hChild, GWL_STYLE) &amp; WS_VISIBLE))
               (::GetWindowLong(hChild, GWL_STYLE) & WS_VISIBLE))
         {
         {
             // see if point hits the child window
             // see if point hits the child window
Line 119: Line 119:


         // hits against child windows always center the tip
         // hits against child windows always center the tip
         if (pTI != NULL &amp;&amp; pTI->cbSize >= sizeof(AfxOldTOOLINFO))
         if (pTI != NULL && pTI->cbSize >= sizeof(AfxOldTOOLINFO))
         {
         {
             // setup the TOOLINFO structure
             // setup the TOOLINFO structure
Line 128: Line 128:


       // set TTF_NOTBUTTON and TTF_CENTERTIP if it isn't a button
       // set TTF_NOTBUTTON and TTF_CENTERTIP if it isn't a button
       if (!(::SendMessage(hWndChild, WM_GETDLGCODE, 0, 0) &amp;
       if (!(::SendMessage(hWndChild, WM_GETDLGCODE, 0, 0) &
                   DLGC_BUTTON))
                   DLGC_BUTTON))
               pTI->uFlags |= TTF_NOTBUTTON|TTF_CENTERTIP;
               pTI->uFlags |= TTF_NOTBUTTON|TTF_CENTERTIP;

Latest revision as of 11:30, 21 July 2020

Knowledge Base


Article ID: 172276

Article Last Modified on 11/21/2006



APPLIES TO

  • Microsoft Foundation Class Library 4.2



This article was previously published under Q172276

SYMPTOMS

Applications that use CWnd::EnableTooltips to use a default CToolTipCtrl do not display the tooltip text for child windows after the Visual Studio Service Pack 1 (SP1) or Service Pack 2 (SP2) has been installed.

Other CToolTipCtrls and Tooltips inside of CToolBars work correctly.

CAUSE

The cbSize parameter of the TOOLINFO struct was changed to be of size AfxOldTOOLINFO to be compatible with older versions of the COMCTL32.DLL.

CWnd::OnToolHitTest() was not changed, and is dependent on the cbSize to be equal to the size of the new TOOLINFO struct. Since cbSize is always set to AfxOldTOOLINFO, this function fails.

RESOLUTION

Override the virtual function CWnd::OnToolHitTest() to take into account the new cbSize value.

STATUS

Microsoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. This bug has been fixed in Visual Studio 97 Service Pack 3.

For more information, please see the following article in the Microsoft Knowledge Base:

170365 INFO: Visual Studio 97 Service Packs - What, Where, and Why


MORE INFORMATION

Here is a sample OnToolHitTest() that implements the workaround:

   #include <WTYPES.H>
   #include "..\src\afximpl.h"

   int CSuperTipFormView::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
   {

      HWND hWndChild = NULL;
      // find child window which hits the point
      // (don't use WindowFromPoint, because it ignores disabled windows)
      // see _AfxChildWindowFromPoint(m_hWnd, point);
      ::ClientToScreen(m_hWnd, &point);
      HWND hChild = ::GetWindow(m_hWnd, GW_CHILD);
      for (; hChild != NULL; hChild = ::GetWindow(hChild, GW_HWNDNEXT))
      {
         if (_AfxGetDlgCtrlID(hChild) != (WORD)-1 &&
               (::GetWindowLong(hChild, GWL_STYLE) & WS_VISIBLE))
         {
            // see if point hits the child window
            CRect rect;
            ::GetWindowRect(hChild, rect);
            if (rect.PtInRect(point))
            {
               hWndChild = hChild;
               break;
            }
         }
      }

      if (hWndChild != NULL)
      {
         // return positive hit if control ID isn't -1
         int nHit = _AfxGetDlgCtrlID(hWndChild);

         // hits against child windows always center the tip
         if (pTI != NULL && pTI->cbSize >= sizeof(AfxOldTOOLINFO))
         {
            // setup the TOOLINFO structure
            pTI->hwnd = m_hWnd;
            pTI->uId = (UINT)hWndChild;
            pTI->uFlags |= TTF_IDISHWND;
            pTI->lpszText = LPSTR_TEXTCALLBACK;

       // set TTF_NOTBUTTON and TTF_CENTERTIP if it isn't a button
       if (!(::SendMessage(hWndChild, WM_GETDLGCODE, 0, 0) &
                  DLGC_BUTTON))
               pTI->uFlags |= TTF_NOTBUTTON|TTF_CENTERTIP;
         }
         return nHit;
      }
      return -1;  // not found
   }
                

REFERENCES

For additional information, please see the following article in the Microsoft Knowledge Base:

167650 FIX: Problems with ToolTips on Windows 95


Keywords: kbbug kbfix kbnoupdate kbtooltip kbuidesign kbvs97sp3fix KB172276