By
Trolleule
Hi,
i want to display a tooltip when i hover over the listview group. It sounds not difficult but i couldn't find a solution and i searched for autoit as well as for c# :/
So i came up with a not so pretty solution:
#include <GUIConstantsEx.au3>
#include <GuiImageList.au3>
#include <GuiListView.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <GuiToolTip.au3>
#include <WinAPI.au3>
Global $idListview, $hWndListView
Global $hToolTip = _GUIToolTip_Create(0, BitOR($_TT_ghTTDefaultStyle, $TTS_BALLOON)); balloon style tooltip
Global Const $LVN_GROUPINFO = ($LVN_FIRST - 88)
Global Const $tagNMLVGROUP = $tagNMHDR & ";int iGroupId;uint iNewState;uint iOldState"
; $LVGS_flags $LVGS_flags
Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam)
#forceref $hWnd, $iMsg, $wParam
Local $tInfo, $tNMHDR = DllStructCreate($tagNMHDR, $lParam), $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
Local $iIDFrom = DllStructGetData($tNMHDR, "IDFrom"), $iCode = DllStructGetData($tNMHDR, "Code")
Switch $hWndFrom
Case $hWndListView
Switch $iCode
; Case $of?????? ; A Group was clicked <---- I need help with this
Case $LVN_GROUPINFO
ConsoleWrite("hier" & @CRLF)
$tInfo = DllStructCreate($tagNMLVGROUP, $lParam)
_DebugPrint("$LVN_GROUPINFO" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode & @CRLF & _
"-->GroupId:" & @TAB & DllStructGetData($tInfo, "iGroupId") & @CRLF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "iNewState") & @CRLF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "iOldState"))
Case $LVN_COLUMNCLICK ; A column was clicked
$tInfo = DllStructCreate($tagNMLISTVIEW, $lParam)
_DebugPrint("$LVN_COLUMNCLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode & @CRLF & _
"-->Item:" & @TAB & DllStructGetData($tInfo, "Item") & @CRLF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
"-->Param:" & @TAB & DllStructGetData($tInfo, "Param"))
; No return value
Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button
$tInfo = DllStructCreate($tagNMITEMACTIVATE, $lParam)
_DebugPrint("$NM_CLICK" & @CRLF & "--> hWndFrom:" & @TAB & $hWndFrom & @CRLF & _
"-->IDFrom:" & @TAB & $iIDFrom & @CRLF & _
"-->Code:" & @TAB & $iCode & @CRLF & _
"-->Index:" & @TAB & DllStructGetData($tInfo, "Index") & @CRLF & _
"-->SubItem:" & @TAB & DllStructGetData($tInfo, "SubItem") & @CRLF & _
"-->NewState:" & @TAB & DllStructGetData($tInfo, "NewState") & @CRLF & _
"-->OldState:" & @TAB & DllStructGetData($tInfo, "OldState") & @CRLF & _
"-->Changed:" & @TAB & DllStructGetData($tInfo, "Changed") & @CRLF & _
"-->ActionX:" & @TAB & DllStructGetData($tInfo, "ActionX") & @CRLF & _
"-->ActionY:" & @TAB & DllStructGetData($tInfo, "ActionY") & @CRLF & _
"-->lParam:" & @TAB & DllStructGetData($tInfo, "lParam") & @CRLF & _
"-->KeyFlags:" & @TAB & DllStructGetData($tInfo, "KeyFlags"))
; No return value
EndSwitch
EndSwitch
Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY
Func _DebugPrint($s_Text, $sLine = @ScriptLineNumber)
ConsoleWrite( _
"!===========================================================" & @CRLF & _
"+======================================================" & @CRLF & _
"-->Line(" & StringFormat("%04d", $sLine) & "):" & @TAB & $s_Text & @CRLF & _
"+======================================================" & @CRLF)
EndFunc ;==>_DebugPrint
If Not StringInStr($CmdLineRaw, "/ErrorStdOut") Then Exit MsgBox($MB_TOPMOST, @ScriptName, 'please run from the editor, thanks', 10)
Example()
Func Example()
Local $aInfo, $hImage, $idListview
$ghui = GUICreate("ListView Group COLLAPSIBLE", 400, 300)
$idListview = GUICtrlCreateListView("", 30, 20, 354, 218);, BitOR($LVS_SHOWSELALWAYS, $LVS_SINGLESEL, $LVS_REPORT, $WS_CLIPSIBLINGS))
$hWndListView = GUICtrlGetHandle($idListview)
; Load images
$hImage = _GUIImageList_Create()
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0xFF0000, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x00FF00, 16, 16))
_GUIImageList_Add($hImage, _GUICtrlListView_CreateSolidBitMap($idListview, 0x0000FF, 16, 16))
_GUICtrlListView_SetImageList($idListview, $hImage, 1)
; Add columns
_GUICtrlListView_AddColumn($idListview, "Column 1", 100)
_GUICtrlListView_AddColumn($idListview, "Column 2", 100)
_GUICtrlListView_AddColumn($idListview, "Column 3", 100)
; Add items
_GUICtrlListView_AddItem($idListview, "Row 1: Col 1", 0)
_GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 2", 1)
_GUICtrlListView_AddSubItem($idListview, 0, "Row 1: Col 3", 2)
_GUICtrlListView_AddItem($idListview, "Row 2: Col 1", 1)
_GUICtrlListView_AddSubItem($idListview, 1, "Row 2: Col 2", 1)
_GUICtrlListView_AddItem($idListview, "Row 3: Col 1", 2)
; Build groups
_GUICtrlListView_EnableGroupView($idListview)
_GUICtrlListView_InsertGroup($idListview, -1, 1, "Group 1", 1)
;~ _GUICtrlListView_SetGroupInfo($idListview, 1, "Group 1", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
_GUICtrlListView_InsertGroup($idListview, -1, 2, "Group 2")
;~ _GUICtrlListView_SetGroupInfo($idListview, 2, "Group 2", 0, $LVGS_COLLAPSIBLE + $LVGS_COLLAPSED) ; <---
_GUICtrlListView_SetItemGroupID($idListview, 0, 1)
_GUICtrlListView_SetItemGroupID($idListview, 1, 2)
_GUICtrlListView_SetItemGroupID($idListview, 2, 2)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
Local $apos = _GUICtrlListView_GetGroupRect($idListview, 2, $LVGGR_LABEL)
Local $test = GUICtrlCreateLabel("a", 2, 2, 10, 17)
Local $val = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_STYLE)
Local $valex = _WinAPI_GetWindowLong(GUICtrlGetHandle($test), $GWL_EXSTYLE)
Local $aha = _WinAPI_CreateWindowEx($valex+$WS_EX_LAYERED, "static", "blabla", $val, $apos[0], $apos[1], 50, 20, $hWndListView)
_GUIToolTip_AddTool($hToolTip, $hWndListView, "This is a ToolTip3", $aha)
GUISetState(@SW_SHOW)
; Loop until the user exits.
Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE
GUIDelete()
EndFunc ;==>Example
Short description: I only created a label with CreateWindowEx which i can append to the listview control and layered it with the $WS_EX_Layered flag so it looks like it's transparent. Then i only added a tooltip tool to that created label.
Hover over the Group 2 text and the Tooltip will be displayed. My question is: does someone know another perhaps much prettier solution?
Thanks in advance