Tecman
Tecman

Reputation: 3009

Win32 tooltip gray line bug in Windows 10

We have been using code that creates classical Win32 multiline tooltips in our legacy VB6 component for many years, since the times of Windows XP. It works fine in all latest versions of MS Windows (7, 8.1) except Windows 10. A parasitic horizontal gray line appears in the tooltip in this OS. The best demonstration of this problem is a tooltip window containing several lines of text (the main tip text is multiline and/or the tooltip has a bold title):

enter image description here

The correct tooltip should look like this (a screen from Windows 8.1):

enter image description here

Below is one more example of the same problem when the tooltip window does not have tile/icon but contains only multiline text:

enter image description here

This parasitic gray line is also present in a single-line tooltip - though it is not noticeable at first look:

enter image description here

What it could be? Is it a bug in Windows 10, or something has changed in the tooltip API?


Below is the code of the method used to initialize a tooltip:

Public Function Create(ByVal ParentHwnd As Long) As Boolean
   Dim lWinStyle As Long

   If m_lTTHwnd <> 0 Then
      DestroyWindow m_lTTHwnd
   End If

   m_lParentHwnd = ParentHwnd

   lWinStyle = TTS_ALWAYSTIP Or TTS_NOPREFIX

   m_lTTHwnd = CreateWindowExA(0&, _
      TOOLTIPS_CLASS, _
      vbNullString, _
      lWinStyle, _
      CW_USEDEFAULT, _
      CW_USEDEFAULT, _
      CW_USEDEFAULT, _
      CW_USEDEFAULT, _
      0&, _
      0&, _
      App.hInstance, _
      0&)

   'now set our tooltip info structure
   Dim tiA As TOOLINFOA
   Dim tiW As TOOLINFOW
   If g_bIsNt Then
      With tiW
         .lSize = Len(tiW)
         .lFlags = TTF_SUBCLASS Or TTF_IDISHWND
         .hWnd = m_lParentHwnd
         .lId = m_lParentHwnd '0
         .hInstance = App.hInstance
         .lpStr = StrPtr(mvarTipText)
      End With
   Else
      With tiA
         .lSize = Len(tiA)
         .lFlags = TTF_SUBCLASS Or TTF_IDISHWND
         .hWnd = m_lParentHwnd
         .lId = m_lParentHwnd
         .hInstance = App.hInstance
         .lpStr = mvarTipText
      End With
   End If

   'add the tooltip structure
   If g_bIsNt Then
      SendMessage m_lTTHwnd, TTM_ADDTOOLW, 0&, tiW
   Else
      SendMessage m_lTTHwnd, TTM_ADDTOOLA, 0&, tiA
   End If

   'if we want a title or we want an icon
   If mvarTitle <> vbNullString Or mvarIcon <> igToolTipIconNone Then
      If g_bIsNt Then
         SendMessage m_lTTHwnd, TTM_SETTITLEW, mvarIcon, ByVal StrPtr(mvarTitle)
      Else
         SendMessage m_lTTHwnd, TTM_SETTITLEA, mvarIcon, ByVal mvarTitle
      End If
   End If

   ' set the time parameters
   SendMessageByLongA m_lTTHwnd, TTM_SETDELAYTIME, TTDT_AUTOPOP, mvarVisibleTime
   SendMessageByLongA m_lTTHwnd, TTM_SETDELAYTIME, TTDT_INITIAL, mvarDelayTime

   'according to MSDN, we should set TTM_SETMAXTIPWIDTH to a positive value
   'to enable multiline tooltips
   SendMessageByLongA m_lTTHwnd, TTM_SETMAXTIPWIDTH, 0, 100000
End Function

Upvotes: 4

Views: 382

Answers (1)

Tecman
Tecman

Reputation: 3009

To solve the problem, we should not set the hwnd field of the TOOLINFO structure. The corresponding part of the code should look like this:

'now set our tooltip info structure
Dim tiA As TOOLINFOA
Dim tiW As TOOLINFOW
If g_bIsNt Then
   With tiW
      .lSize = Len(tiW)
      .lFlags = TTF_SUBCLASS Or TTF_IDISHWND
      .lId = m_lParentHwnd
      .hInstance = App.hInstance
      .lpStr = StrPtr(mvarTipText)
   End With
Else
   With tiA
      .lSize = Len(tiA)
      .lFlags = TTF_SUBCLASS Or TTF_IDISHWND
      .lId = m_lParentHwnd
      .hInstance = App.hInstance
      .lpStr = mvarTipText
   End With
End If

Upvotes: 1

Related Questions