Floooooo24 Posted October 27, 2022 Posted October 27, 2022 Hello Together, I created an Treeview and added an Context Menu to interacte with an Item. But after an Item was klicked with the right Mousebutton, the funktion _GUICtrlTreeView_GetSelection($gTreeview)) only returns "0x000000". If I open an MsgBox, and close this, the Funktion will give the right handle. Is there a way to fix this? Case $gTreeviewContextNew MsgBox(0, "Stupid way to do this", "Close this", 1) MsgBox(0, "Stupid way to do this", _GUICtrlTreeView_GetSelection($gTreeview)) Thank you.
Dan_555 Posted October 27, 2022 Posted October 27, 2022 (edited) Your code does not help to solve anything. Somewhere in this forum there is a treeview with right click menu code. Here is a copy of it: expandcollapse popup#include <GUIConstantsEx.au3> #include <WindowsConstants.au3> #include <TreeViewConstants.au3> #include <GuiTreeView.au3> Opt('MustDeclareVars', 1) Global $cTreeView, $tNMHDR, $hWndFrom, $iIDFrom, $iCode _Main() Func _Main() Local $myArray[10][2], $nMsg, $iIndex, $sText, $Char Local $iTVStyles = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, _ $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes) Local $mainform = GUICreate("TreeView", 400, 300) $cTreeView = GUICtrlCreateTreeView(10, 10, 380, 280, $iTVStyles, $WS_EX_CLIENTEDGE) Local $var = GUICtrlCreateContextMenu($cTreeView) Local $preview = GUICtrlCreateMenuItem("Preview", $var) For $i = 1 To UBound($myArray) - 1 $Char = Chr(64 + $i) $myArray[$i][0] = "This element contains " & $Char $myArray[$i][1] = GUICtrlCreateTreeViewItem($myArray[$i][0], $cTreeView) Next GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") GUISetState(@SW_SHOW) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $preview $iIndex = GUICtrlRead($cTreeView) $sText = GUICtrlRead($cTreeView, 1);_GUICtrlTreeView_GetText($hTreeView, $iIndex) MsgBox(0, "Preview", "Index: " & $iIndex & @CRLF & "ItemText: " & $sText) EndSwitch WEnd EndFunc ;==>_Main Func WM_NOTIFY($hWnd, $iMsg, $wParam, $lParam) #forceref $hWnd, $iMsg, $wParam $tNMHDR = DllStructCreate($tagNMHDR, $lParam) $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom") $iIDFrom = DllStructGetData($tNMHDR, "IDFrom") $iCode = DllStructGetData($tNMHDR, "Code") Switch $iIDFrom Case $cTreeView Switch $iCode Case $NM_RCLICK Local $tPoint = _WinAPI_GetMousePos(True, $hWndFrom), $tHitTest $tHitTest = _GUICtrlTreeView_HitTestEx($hWndFrom, DllStructGetData($tPoint, 1), DllStructGetData($tPoint, 2)) If BitAND(DllStructGetData($tHitTest, "Flags"), $TVHT_ONITEM) Then _GUICtrlTreeView_SelectItem($hWndFrom, DllStructGetData($tHitTest, 'Item')) EndIf EndSwitch EndSwitch Return $GUI_RUNDEFMSG EndFunc ;==>WM_NOTIFY Edited October 27, 2022 by Dan_555 Some of my script sourcecode
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