加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Windows > 正文

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

发布时间:2020-12-14 05:43:54 所属栏目:Windows 来源:网络整理
导读:自 Windows XP时代以来,我们一直使用在我们的传统VB6组件中创建经典Win32多线工具提示的代码.除了Windows 10之外,它在所有最新版本的MS Windows(7,8.1)中都能正常工作.在此操作系统的工具提示中会出现寄生水平灰线.此问题的最佳演示是包含多行文本的工具提示
自 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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读