Jump to content

Tooltips on ListView headers


Recommended Posts

Hi -

I've found an older post from doudou on this topic in example section - but I can't get this working...

Please, could someone enlight me? I'm not able to solve it on my own... :-(

 

Edited by supersonic
Link to comment
Share on other sites

  • Moderators

supersonic,

Why not use the standard GUIToolTip UDF to do it? Here is a modified version of the _GUIToolTip_Create example in the Help file which has different tooltips on the header and body of the ListView:

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
#include <GuiListView.au3>

Example()

Func Example()
    Local $hGUI = GUICreate(StringTrimRight(@ScriptName, StringLen(".exe")), 270, 200)

    Local $idButton = GUICtrlCreateButton("Add", 30, 32, 75, 25)
    Local $hButton = GUICtrlGetHandle($idButton)
    Local $idClear = GUICtrlCreateButton("Clear", 30, 72, 75, 25)
    Local $hClear = GUICtrlGetHandle($idClear)
    Local $idMyListView = GUICtrlCreateListView("Item 1", 120, 32, 121, 97)
    Local $hMyListView = GUICtrlGetHandle($idMyListView)

    Local $hMyHeader = _GUICtrlListView_GetHeader($hMyListView) ; <<<<<<<<<<<

    GUICtrlCreateListViewItem("Item 1", $idMyListView)
    Local $idClose = GUICtrlCreateButton("Exit button", 80, 150, 110, 28)
    Local $hClose = GUICtrlGetHandle($idClose)

    ; Create 2 tooltip controls
    Local $hToolTip1 = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
    Local $hToolTip2 = _GUIToolTip_Create(0) ; default style tooltip
    _GUIToolTip_SetMaxTipWidth($hToolTip2, 100) ; this allows multiline tooltips to be used with $hToolTip2
    ; add tools to the tooltip controls
    _GUIToolTip_AddTool($hToolTip1, 0, "Adds an item to the list", $hButton)
    _GUIToolTip_AddTool($hToolTip1, 0, "Exit the script", $hClose)
    _GUIToolTip_AddTool($hToolTip1, 0, "The listview header", $hMyHeader) ; <<<<<<<<<<<<<<<<
    _GUIToolTip_AddTool($hToolTip2, 0, "The listview", $hMyListView)
    _GUIToolTip_AddTool($hToolTip2, 0, "Clears the list", $hClear)
    _GUIToolTip_AddTool($hToolTip2, 0, "Multiline tooltip" & @CRLF & "for the GUI", $hGUI) ; Multiline ToolTip
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $idButton

                GUICtrlSetData($idMyListView, 'The Add button was pressed"|')
            Case $idClear

                GUICtrlSetData($idMyListView, '')
            Case $idClose, $GUI_EVENT_CLOSE
                ExitLoop

        EndSwitch

    WEnd

    ; Destroy the tooltip controls
    _GUIToolTip_Destroy($hToolTip1)
    _GUIToolTip_Destroy($hToolTip2)
    GUIDelete($hGUI)
EndFunc   ;==>Example

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

supersonic,

Then you need to do something like this:

#include <GUIConstantsEx.au3>
#include <GUIToolTip.au3>
#include <GuiListView.au3>
#include <WinAPI.au3>

#include <Array.au3>

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 300, 300)
$hHeader = _GUICtrlListView_GetHeader($cLV)
GUICtrlCreateListViewItem("Item 1", $cLV)

$hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
_GUIToolTip_AddTool($hToolTip, 0, "LV Header", $hHeader)

GUISetState(@SW_SHOW)

; gte array with column right side posiitons

Global $aCol_Pos[3]
For $i = 0 To 2
    $aCol_Pos[$i] = _GUICtrlListView_GetColumnWidth($cLV, $i)
    If $i > 0 Then
        $aCol_Pos[$i] += $aCol_Pos[$i - 1]
    EndIf

Next
; Just for display
_ArrayDisplay($aCol_Pos, "", Default, 8)

Global $tPoint = DllStructCreate($tagPOINT)
Global $iCol = -1

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

    EndSwitch



    _UpDate_Header_Tool()

WEnd



_GUIToolTip_Destroy($hToolTip)

Func _UpDate_Header_Tool()
    ; Get mouse position
    $aMPos = MouseGetPos()
    DllStructSetData($tPoint, "x", $aMPos[0])
    DllStructSetData($tPoint, "y", $aMPos[1])
    ; Check if over header
    $hHandle = _WinAPI_WindowFromPoint($tPoint)
    If $hHandle = $hHeader Then
        ; Get header position
        $aHPos = WinGetPos($hHeader)
        ; Check column under cursor
        For $i = 0 To 2
            If $aMPos[0] - $aHPos[0] < $aCol_Pos[$i] Then
                ; if column has changed
                If $i <> $iCol Then
                    ; Update tooltip text
                    _GUIToolTip_UpdateTipText($hToolTip, 0, $hHeader, "Column " & $i )
                    $iCol = $i

                EndIf

                ExitLoop

            EndIf

        Next
    EndIf
EndFunc

You could always run the function only when the mouse moves if you wanted to be more elegant, but I have my hands full with Korean spammers at the moment.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

M23,

I embedded your code into my script. Works so far. But if any column is resized the col. widths in '$aCol_Pos' will become incorrect. Is there a WM_NOTIFY trigger for LV col. resizing?

 

Edited by supersonic
Link to comment
Share on other sites

  • Moderators

supersonic,

Is there a WM_NOTIFY trigger for LV col. resizing?

Of course - have you done any research to see what it might be?

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GUIToolTip.au3>
#include <GuiListView.au3>
#include <HeaderConstants.au3>
#include <WinAPI.au3>

#include <Array.au3>

Global $bCols_Resize = False, $aCol_Pos[3]

$hGUI = GUICreate("Test", 500, 500)

$cLV = GUICtrlCreateListView("Column 0|Column 1|Column 2", 10, 10, 300, 300)
$hHeader = _GUICtrlListView_GetHeader($cLV)
GUICtrlCreateListViewItem("Item 1", $cLV)

$hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
_GUIToolTip_AddTool($hToolTip, 0, "LV Header", $hHeader)

GUISetState(@SW_SHOW)

_Size_Cols()

Global $tPoint = DllStructCreate($tagPOINT)
Global $iCol = -1

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop



    EndSwitch



    ; Have cols been resized?
    If $bCols_Resize Then
        $bCols_Resize = False
        _Size_Cols()
    EndIf



    ; Check if header tootip required and set correct text
    _UpDate_Header_Tool()

WEnd



_GUIToolTip_Destroy($hToolTip)

Func _WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)

    ; Get details of message
    Local $tNMHEADER = DllStructCreate($tagNMHEADER, $lParam)
    ; Look for end of header resize code
    $iCode = DllStructGetData($tNMHEADER, "Code")
    Switch $iCode

        Case $HDN_ENDTRACKW
            ; Set flag
            $bCols_Resize = True
    EndSwitch



EndFunc   ;==>_WM_NOTIFY

Func _Size_Cols()

    ; Get array with column right side posiitons

    For $i = 0 To 2
        $aCol_Pos[$i] = _GUICtrlListView_GetColumnWidth($cLV, $i)
        If $i > 0 Then
            $aCol_Pos[$i] += $aCol_Pos[$i - 1]
        EndIf

    Next
    ; Just for display
    _ArrayDisplay($aCol_Pos, "", Default, 8)

EndFunc   ;==>_Size_Cols

Func _UpDate_Header_Tool()
    ; Get mouse position
    $aMPos = MouseGetPos()
    DllStructSetData($tPoint, "x", $aMPos[0])
    DllStructSetData($tPoint, "y", $aMPos[1])
    ; Check if over header
    $hHandle = _WinAPI_WindowFromPoint($tPoint)
    If $hHandle = $hHeader Then
        ; Get header position
        $aHPos = WinGetPos($hHeader)
        ; Check column under cursor
        For $i = 0 To 2
            If $aMPos[0] - $aHPos[0] < $aCol_Pos[$i] Then
                ; if column has changed
                If $i <> $iCol Then
                    ; Update tooltip text
                    _GUIToolTip_UpdateTipText($hToolTip, 0, $hHeader, "Column " & $i)
                    $iCol = $i

                EndIf

                ExitLoop

            EndIf

        Next
    EndIf

EndFunc   ;==>_UpDate_Header_Tool

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

supersonic,

Well done. If you did not realise - you will see that there is some code inside the top spoiler of my last post which shows another way of doing it.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

  • Moderators

supersonic,

 '$HDN_ENDTRACKW' seems to trigger only when resizing cols.

Exactly. I am not sure what "-12" is, but I think it is a general mouse notification.

M23 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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...