简体   繁体   English

检测气球工具提示是否可见

[英]Detecting if balloon tooltip is visible

My program makes heavy use of the Windows build-in balloon tooltips, but on some system they are just not displayed. 我的程序大量使用Windows内置气球工具提示,但在某些系统上只是不显示它们。 This can have so many different causes (for example: EnableBalloonTips, ShowInfoTip, DisablePreviewDesktop, TaskbarNoNotification are all different registry keys that can have influence), that its almost imposible to correct those settings during installation. 这可能有很多不同的原因(例如:EnableBalloonTips,ShowInfoTip,DisablePreviewDesktop,TaskbarNoNotification都是可以影响的不同注册表项),几乎无法在安装过程中更正这些设置。

So my alternative was to simply test if the balloon is visible, and if not, display a message they should contact support. 因此,我的替代方法是简单地测试气球是否可见,如果看不到,则显示一条消息,他们应该联系支持人员。 However all methods I use on the hWnd of the tooltip (IsWindowVisible, GetActiveWindow, etc) all return that the balloon is visible, even in cases when its not. 但是,我在工具提示的hWnd上使用的所有方法(IsWindowVisible,GetActiveWindow等)均返回该气球可见,即使在气球不可见的情况下也是如此。 I suspect this has something to do with Windows assigning the parent's hWnd to the balloon, so how can I check its actually displayed correctly? 我怀疑这与Windows将父项的hWnd分配给气球有关,因此我如何检查其实际显示是否正确?

Public Sub Create(ByVal hWndParent As Long, _
  Optional ByVal bAlwaysTip As Boolean = True, _
  Optional ByVal bBalloonTip As Boolean = True)

  Dim nFlags As Long

  ' Wir möchten kein normales Fenster :-)
  nFlags = WS_POPUP Or TTS_NOPREFIX

  ' Falls der ToolTip auch bei deaktiviertem 
  ' Control erscheinen soll...
  If bAlwaysTip Then nFlags = nFlags Or TTS_ALWAYSTIP

  ' Falls ein "moderner" Balloon-ToolTip erwünscht...
  If bBalloonTip Then nFlags = nFlags Or TTS_BALLOON

  ' Window-Handle erstellen  
  m_hWnd = CreateWindowEx(0, "tooltips_class32", 0, _
    nFlags, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, _
    CW_USEDEFAULT, hWndParent, 0, App.hInstance, 0)

  ' maximale Fensterbreite festlegen
  SendMessageLong m_hWnd, TTM_SETMAXTIPWIDTH, 0, m_lMaxWidth
End Sub

Public Sub SetToolTipText(hWnd As Long, ByVal strText As String)

    Dim udtToolInfo As TOOLINFO
    With udtToolInfo
        .hWnd = hWnd
        .uId = hWnd
        .lpszText = strText
        .cbSize = Len(udtToolInfo)
    End With

    SendMessage m_hWnd, TTM_UPDATETIPTEXTA, 0, udtToolInfo

End Sub

You should indeed isolate the registry keys that affect your application and make the appropriate changes. 实际上,您应该隔离影响应用程序的注册表项并进行适当的更改。 If that's what you end up doing through support, maybe it's natural to just make the changes forcibly. 如果那是您最终通过支持所做的工作,那么强行进行更改也许是很自然的。

But what would be an even better idea is to write your own solution, as in, create your own window that is directly tailored to your application. 但是,最好的办法是编写自己的解决方案,例如创建直接针对您的应用程序定制的窗口。 It would give you the power you'd want without Windows tackling you all the time. Windows不会一直困扰您,它会为您提供所需的功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM