Linda Posted May 15, 2009 Share Posted May 15, 2009 (edited) Hi all I have been searching and i see that there are some post just below this one talking about how to control things dependent on the checkbox, but is it possible to get the control case for a embedded checkbox in a TreeView ?? I can only find $NM_CLICK but that is not even close to the situation that a user has used the checkbox. Something like this Func _WM_NOTIFY($hWndGUI, $MsgID, $wParam, $lParam) #forceref $hWndGUI, $MsgID, $wParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview $hWndTreeview = $hTreeView ;If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView) global $varFile,$messageHint,$return_value,$oIEgoto Local $tNMHDR, $event, $hwndFrom, $code, $i_idNew, $dwFlags, $lResult, $idFrom, $i_idOld Local $tNMTOOLBAR, $tNMTBHOTITEM $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hwndFrom = DllStructGetData($tNMHDR, "hWndFrom") $idFrom = DllStructGetData($tNMHDR, "IDFrom") $code = DllStructGetData($tNMHDR, "Code") Switch $hwndFrom Case $hWndTreeview Switch $code [b]case $NM_CLICK[/b] ??? Do something with the TreeItemID here.. To my second problem about getting the current TreeView Item when using HitTest method. $MousePos = MouseGetPos() $Hit = _GUICtrlTreeView_HitTestItem($hTreeView, $MousePos[0], $MousePos[1]) I always get focus problems, i.e _GUICtrlTreeView_SetSelected($hTreeView, $Hit) can actually select two items (just below the current selected) even if i only clicked one. Thanks in advance and have a nice day! /Linda Edited May 15, 2009 by Linda Link to comment Share on other sites More sharing options...
Linda Posted May 15, 2009 Author Share Posted May 15, 2009 Found this solution but still not a GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY") case. But it works. GUISetOnEvent($GUI_EVENT_CLOSE, "TreeEvents") GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "TreeEvents") Func TreeEvents() Switch @GUI_CtrlId Case $GUI_EVENT_CLOSE _GUICtrlTreeView_Destroy($hTreeView) GUIDelete() Exit Case $GUI_EVENT_PRIMARYDOWN Local $tMPos = _WinAPI_GetMousePos(True, $hTreeView) Local $tHitTest = _GUICtrlTreeView_HitTestEx($hTreeView, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) Local $iFlags = DllStructGetData($tHitTest, "Flags") If BitAND($iFlags, $TVHT_ONITEMSTATEICON) <> 0 Then Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, DllStructGetData($tMPos, 1), DllStructGetData($tMPos, 2)) ConsoleWrite(_GUICtrlTreeView_GetText($hTreeView, $iItem) & " is checked = " & _GUICtrlTreeView_GetChecked($hTreeView, $iItem) & @LF) EndIf EndSwitch EndFunc Link to comment Share on other sites More sharing options...
GaryFrost Posted May 16, 2009 Share Posted May 16, 2009 Try: expandcollapse popup#AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 #include <GuiConstantsEx.au3> #include <GuiTreeView.au3> #include <WindowsConstants.au3> Opt('MustDeclareVars', 1) $Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work Global $hTreeView, $fClicked = False, $i_Item _Main() Func _Main() Local $hItem Local $iStyle = BitOR($TVS_EDITLABELS, $TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_CHECKBOXES) GUICreate("TreeView Create Item Checked?", 400, 300) $hTreeView = GUICtrlCreateTreeView(2, 2, 396, 268, $iStyle, $WS_EX_CLIENTEDGE) GUISetState() GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") _GUICtrlTreeView_BeginUpdate($hTreeView) For $x = 1 To Random(2, 10, 1) $hItem = _GUICtrlTreeView_Add($hTreeView, 0, StringFormat("[%02d] New Item", $x)) For $y = 1 To Random(2, 10, 1) _GUICtrlTreeView_AddChild($hTreeView, $hItem, StringFormat("[%02d] New Child", $y)) Next Next _GUICtrlTreeView_EndUpdate($hTreeView) _GUICtrlTreeView_SetFocused($hTreeView, 0) ; Loop until user exits While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case Else If $fClicked Then If _GUICtrlTreeView_GetChecked($hTreeView, $i_Item) Then _DebugPrint(StringFormat("State for Item %d? %s", $i_Item, "Is Checked")) Else _DebugPrint(StringFormat("State for Item %d? %s", $i_Item, "Is NOT Checked")) EndIf $fClicked = False EndIf EndSwitch WEnd GUIDelete() EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) #forceref $hWnd, $iMsg, $iwParam Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeview, $i_opt, $i_pos $hWndTreeview = $hTreeView If Not IsHWnd($hTreeView) Then $hWndTreeview = GUICtrlGetHandle($hTreeView) $tNMHDR = DllStructCreate($tagNMHDR, $ilParam) $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom")) $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $hWndFrom Case $hWndTreeview Switch $iCode Case $NM_CLICK ; The user has clicked the left mouse button within the control _DebugPrint("$NM_CLICK" & @LF & "--> hWndFrom:" & @TAB & $hWndFrom & @LF & _ "-->IDFrom:" & @TAB & $iIDFrom & @LF & _ "-->Code:" & @TAB & $iCode) $i_opt = Opt("MouseCoordMode", 2) $i_pos = MouseGetPos() If _GUICtrlTreeView_HitTest($hWndTreeview, $i_pos[0], $i_pos[1]) = 64 Then $fClicked = True $i_Item = _GUICtrlTreeView_HitTestItem($hWndTreeview, $i_pos[0], $i_pos[1]) EndIf Opt("MouseCoordMode", $i_opt) ;~ Return 1 ; nonzero to not allow the default processing Return 0 ; zero to allow the default processing EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Func _DebugPrint($s_text, $line = @ScriptLineNumber) ConsoleWrite( _ "!===========================================================" & @LF & _ "+======================================================" & @LF & _ "-->Line(" & StringFormat("%04d", $line) & "):" & @TAB & $s_text & @LF & _ "+======================================================" & @LF) EndFunc ;==>_DebugPrint SciTE for AutoItDirections for Submitting Standard UDFs Don't argue with an idiot; people watching may not be able to tell the difference. Link to comment Share on other sites More sharing options...
Linda Posted May 16, 2009 Author Share Posted May 16, 2009 Gary, Thanks for that! Much appreciated! The switching between $fClicked = True and false seems to save us here Frost..never stop posting in this forum Link to comment Share on other sites More sharing options...
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