Jump to content

How To Clear ListView ToolTips?


Recommended Posts

Hey all,

Hopefully an easy question...if I have a listview with tooltips enabled and I move the mouse cursor off the listview, how can I clear the tooltip? In the reproducer below, the tooltip remains in almost every circumstance - even if I minimize the gui, the tooltip still overlays other windows. I'd like it to be cleared if I'm outside of the listview, ideally.

Thanks.

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>

$hGUI = GUICreate("ToolTip test", 250, 200)
$idListView = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 235, 175, $WS_VISIBLE, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))

For $i = 0 To 5
    GUICtrlCreateListViewItem(StringFormat("Item %s|abc%s|def%s", $i, $i, $i), $idListView)
Next

GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $IMsg, $iwParam, $ilParam)
    #forceref $hWnd, $IMsg, $iwParam
    Local $hwndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo,  $gText, $aPos

    $hWndListView = $idListView
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hwndFrom = HWnd(DllStructGetData($tNMHDR, "hwndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "idFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hwndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_HOTTRACK; Sent by a list-view control When the user moves the mouse over an item
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    If Not ($iItem = -1 Or $iSubItem = -1) Then
                        $sText = _GUICtrlListView_GetItemText($hwndFrom, $iItem, $iSubItem)
                        ToolTip($sText)
                    Else
                        ToolTip("")
                    EndIf
                    Return 1; the item will not be selected.
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc

 

Link to comment
Share on other sites

Hi.  maybe this.

#include <GUIConstantsEx.au3>
#include <GUIListView.au3>
#include <WindowsConstants.au3>


Global $gToolExist=False ;just for avoid set tooltip to "" when not exist
$hGUI = GUICreate("ToolTip test", 250, 200)
$idListView = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 235, 175, $WS_VISIBLE, BitOR($LVS_EX_FULLROWSELECT, $LVS_EX_INFOTIP))

For $i = 0 To 5
    GUICtrlCreateListViewItem(StringFormat("Item %s|abc%s|def%s", $i, $i, $i), $idListView)
Next

GUISetState(@SW_SHOW, $hGUI)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Local $aInfo = 0
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop
        Case $GUI_EVENT_MOUSEMOVE
            $aInfo = GUIGetCursorInfo()
            If $aInfo[4] <> $idListView and $gToolExist=True Then
                ToolTip("")
                $gToolExist=False
            EndIf
    EndSwitch
WEnd

Func WM_NOTIFY($hWnd, $IMsg, $iwParam, $ilParam)
    #forceref $hWnd, $IMsg, $iwParam
    Local $hwndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView, $tInfo, $gText, $aPos

    $hWndListView = $idListView
    If Not IsHWnd($hWndListView) Then $hWndListView = GUICtrlGetHandle($hWndListView)

    $tNMHDR = DllStructCreate($tagNMHDR, $ilParam)
    $hwndFrom = HWnd(DllStructGetData($tNMHDR, "hwndFrom"))
    $iIDFrom = DllStructGetData($tNMHDR, "idFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")

    Switch $hwndFrom
        Case $hWndListView
            Switch $iCode
                Case $LVN_HOTTRACK; Sent by a list-view control When the user moves the mouse over an item
                    $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam)
                    $iItem = DllStructGetData($tInfo, "Item")
                    $iSubItem = DllStructGetData($tInfo, "SubItem")
                    If Not ($iItem = -1 Or $iSubItem = -1) Then
                        $sText = _GUICtrlListView_GetItemText($hwndFrom, $iItem, $iSubItem)
                        ToolTip($sText)
                    Else
                        ToolTip("")
                    EndIf
                    $gToolExist=True
                    Return 1; the item will not be selected.
            EndSwitch

    EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc   ;==>WM_NOTIFY

Saludos

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

×
×
  • Create New...