winapi – Windows 10中的Win32工具提示灰线错误

前端之家收集整理的这篇文章主要介绍了winapi – Windows 10中的Win32工具提示灰线错误前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
Windows XP时代以来,我们一直使用在我们的传统VB6组件中创建经典Win32多线工具提示代码.除了Windows 10之外,它在所有最新版本的MS Windows(7,8.1)中都能正常工作.在此操作系统的工具提示中会出现寄生水平灰线.此问题的最佳演示是包含多行文本的工具提示窗口(主要提示文本为多行和/或工具提示具有粗体标题):

enter image description here

正确的工具提示应如下所示(Windows 8.1中的屏幕):

enter image description here

当工具提示窗口没有图块/图标但仅包含多行文本时,下面是另一个相同问题的示例:

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,_
      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,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,ByVal mvarTitle
      End If
   End If

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

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

解决方法

解决这个问题,我们不应该设置TOOLINFO结构的hwnd字段.代码的相应部分应如下所示:

'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

猜你在找的Windows相关文章