d0n Posted October 19, 2009 Posted October 19, 2009 how do i call a function when i click on a listview? Should i be using Hotitem? can someone make a shorter sample with hotitem ?
BugFix Posted October 19, 2009 Posted October 19, 2009 (edited) Here an example: (Note: You can not use both, $LVN_HOTTRACK and $NM_CLICK, together) expandcollapse popup#include <ListViewConstants.au3> #include <StructureConstants.au3> #include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <GUIListView.au3> $gui = GUICreate('test') $hListView = GUICtrlCreateListView('Column1|Column2', 10, 10, 300, 200) _GUICtrlListView_SetColumnWidth($hListView, 0, 146) _GUICtrlListView_SetColumnWidth($hListView, 1, $LVSCW_AUTOSIZE_USEHEADER) For $i = 1 To 10 GUICtrlCreateListViewItem('Row ' & $i & ' Column 1|Row ' & $i & ' Column 2', $hListView) Next GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") Do $msg = GUIGetMsg() Until $msg = $GUI_EVENT_CLOSE Func ListView_HOTTRACK($iSubItem) Local $HotItem = _GUICtrlListView_GetHotItem($hListView) If $HotItem <> -1 Then _ToolTipMouseExit("Hoover Item: " & $HotItem & " SubItem: " & $iSubItem & @CRLF & _ 'Content: ' & _GUICtrlListView_GetItemText($hListView, $HotItem, $iSubItem), 500) EndFunc ;==>ListView_HOTTRACK Func ListView_CLICK($aInfo) ConsoleWrite('clicked: row ' & $aInfo[0] & ' - column ' & $aInfo[1] & @CRLF) EndFunc Func _ToolTipMouseExit($TEXT, $TIME=-1, $x=-1, $y=-1, $TITLE='', $ICON=0, $OPT='') If $TIME = -1 Then $TIME = 3000 Local $start = TimerInit(), $pos0 = MouseGetPos() If ($x = -1) Or ($y = -1) Then ToolTip($TEXT, $pos0[0], $pos0[1], $TITLE, $ICON, $OPT) Else ToolTip($TEXT, $x, $y, $TITLE, $ICON, $OPT) EndIf Do Sleep(50) $pos = MouseGetPos() Until (TimerDiff($start) > $TIME) Or _ (Abs($pos[0] - $pos0[0]) > 10 Or _ Abs($pos[1] - $pos0[1]) > 10) ToolTip('') EndFunc ;_ToolTipMouseExit Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndListView $hWndListView = $hListView If Not IsHWnd($hListView) Then $hWndListView = GUICtrlGetHandle($hListView) $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 Local $tInfo = DllStructCreate($tagNMLISTVIEW, $ilParam) ListView_HOTTRACK(DllStructGetData($tInfo, "SubItem")) ;~ Case $NM_CLICK ; Sent by a list-view control when the user clicks an item with the left mouse button ;~ Local $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam) ;~ Local $aInfo[2] = [DllStructGetData($tInfo, "Index"), _ ;~ DllStructGetData($tInfo, "SubItem")] ;~ ListView_CLICK($aInfo) EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited October 19, 2009 by BugFix Best Regards BugFix
d0n Posted October 19, 2009 Author Posted October 19, 2009 thanks, i was hoping there be a simpler way but this works
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now