Fixed a bug caused by a series of lines in Win32 in Windows 10

We used code that creates the classic Win32 multi-line hints in our legacy VB6 component for many years, starting from the time of Windows XP. It works fine in all recent versions of MS Windows (7, 8.1), except for Windows 10. A spurious 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 body of the tooltip is multi-line and / or the tooltip has a bold title):

enter image description here

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

enter image description here

Below is another example of the same problem when the tooltip does not have a fragment / icon, but contains only multi-line text:

enter image description here

- :

enter image description here

? Windows 10, - API ?


, :

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
+4
1

, hwnd TOOLINFO. :

'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
+1

Source: https://habr.com/ru/post/1612905/


All Articles