Jump to content

Reading TrayTips


Recommended Posts

Is there any way to read traytips, or sense whether one is still active? I'm certainly not aware of a way of doing it.

The problem arises when an application uses traytips to notify the user of different conditions. Several notifications may be given over a period of time, and while the program knows what notifications it's giving out, I'm not aware of a way of detecting whether the previous traytip has been closed. Otherwise, of course, it just gets overwritten with the next message, and the user missing out.

If there isn't, then I'll have to steer away from traytips when notifying users of more than one essential message and use other methods.

Link to comment
Share on other sites

Link to comment
Share on other sites

CS, surely you haven't fallen into being a newb like everybody else...

What is a Traytip, really?

Link to comment
Share on other sites

CS, surely you haven't fallen into being a newb like everybody else...

What is a Traytip, really?

<{POST_SNAPBACK}>

What do you mean? All I know is that the following fails

Opt("WinTitleMatchMode", 4)
$title = WinGetTitle("classname=tooltips_class32)
MsgBox(4096,"Hmm", $title)

I have also tried WinGetText("handle=000B0140") where I obtained the handle with WinSpy++

What am I overlooking? :lmao:

Edited by CyberSlug
Use Mozilla | Take a look at My Disorganized AutoIt stuff | Very very old: AutoBuilder 11 Jan 2005 prototype I need to update my sig!
Link to comment
Share on other sites

What do you mean?  All I know is that the following fails

Opt("WinTitleMatchMode", 4)
$title = WinGetTitle("classname=tooltips_class32)
MsgBox(4096,"Hmm", $title)

I have also tried WinGetText("handle=000B0140") where I obtained the handle with WinSpy++

What am I overlooking?  o:)

<{POST_SNAPBACK}>

Wow. :lmao:

I can't find the window with anything but Spy++. From my looking, it seems its just a regular tooltip created as a Balloon Tip which Explorer always has in existence. However, I can't find it using any of AutoIt's functions nor can I find it using FindWindow/FindWindowEx API calls. It seems that Spy++ is using some alternate method for retrieving the text of the window and is thus mis-leading us into believing that the text is the title. Apparently Microsoft decided to make this little gem disobey its rules and so-called standard practices as well.

Link to comment
Share on other sites

Ah, so no luck then? Sounds like traytips are only suitable for situations where you're prepared to have subsequent message clobber previous ones.

And I think CyberSlug has earned back his non newb status, or else we're all newbs when it comes to this topic.

Link to comment
Share on other sites

This is a very weird thing. Tooltips work correctly. Balloon Tips also work correctly. I have a build with some extensions to ToolTip and everything works fine both in ToolTip mode and Balloon mode. My guess is Explorer, which owns the Balloon Tip used during a TrayTip, is doing something odd with the tip. This is causing the text matching facilities to fail.

I had assumed a TrayTip would be readable since all its bretheren are (Tooltips). However, I forgot to account for it being part of a Microsoft product which are notorious for defining API's they don't use. Somehow Spy++ properly reports the text when viewing an overview of the windows in the system, further adding to the confusion.

Now then. If you are really serious about this, I know of a way to determine if the window is visible or not, but it's a lot more work. The code below is not sufficient, however, it does work. There needs to be an addition made. Whenever a tooltip window is found to have the TTS_BALLOON style, then the parent of that tooltip needs to be checked using the API call (Via DllCall) Getwindow. Compare the returned HWND to the HWND of Shell_TrayWnd. It is possible, albeit very unlikely, but still possible, that another tooltip with the TTS_BALLOON style may exist in the system at the same time. If this other window happens to be higher in the Z-Order, you'll get the wrong window. I noticed when testing this code that Visual Studio .NET had a couple balloon tips in the system.

When running this code, you should get two message boxes with the title "Good".

Global Const $GWL_STYLE = -16
Global Const $TTS_BALLOON = 0x40

Main()

Func Main()
    Local $hWnd = 0
    Opt("WinTitleMatchMode", 4)
    Local $a = WinList("classname=tooltips_class32")
    For $i = 1 To UBound($a)-1
        Local $style = _GetWindowLong($a[$i][1], $GWL_STYLE)
        If BitAND($style, $TTS_BALLOON) Then 
            $hWnd = $a[$i][1]
            ExitLoop
        EndIf
    Next
    If $hWnd = 0 Then
        MsgBox(4096, "Error", "Couldn't find window")
        Return
    EndIf
    TrayTip("Test", "Test", 5, 16)
    Sleep(500)
    If BitAND(WinGetState($hWnd), 2) Then MsgBox(4096, "Good", "Window is visible")
    TrayTip("", "", 5, 16); Force clear
    Sleep(500)
    If Not BitAND(WinGetState($hWnd), 2) Then MsgBox(4096, "Good", "Window is NOT visible")
EndFunc

#Region _GetWindowLong()
; ===================================================================
; _GetWindowLong($hWnd, $index)
;
; Retreives an attribute of the specified window.
; Parameters:
;   $hWnd - IN - Handle to the window.
;   $index - IN - The flag to get.
;   Success - The return value of SetWindowLong which may be 0 or the a 32-bit value (can be 0).
;   Failure - Sets @error if DllCall() fails.
; ===================================================================
Func _GetWindowLong($hWnd, $index)
    Local $ret = DllCall("user32.dll", "long", "GetWindowLong", "hwnd", $hWnd, "int", $index )
    If @error Then
        SetError(@error)
        Return 0
    EndIf
    Return $ret[0]
EndFunc; _GetWindowLong()
#EndRegion _GetWindowLong()
Edited by Valik
Link to comment
Share on other sites

  • 9 months later...

Sorry for bumping this, but this is exactly what I need.

So it is in any way possible at all to retrieve the text from the balloon tip?

The code you posted Valik works for the balloon I am trying to retrieve from, but I really need the text, in any way possible.

Link to comment
Share on other sites

It's kind of complex. Once you have a handle to the balloon tip (My code can find that), you need to create a structure using DllStructCreate(). The structure that needs created is the TOOLINFO structure. Once you've done that, you need to use DllCall() on the Windows API function SendMessage() to send a TTM_GETTEXT message. You pass the structure you created previously during this message call. The text of the balloon tip will be filled in the structure once the function completes. This approach requires the beta version of AutoIt (For DllStructCreate()). You will also need to look up the details of the structure and message on MSDN. I'm sure other members of the forum can help with DllStruct and DllCall.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...