Jump to content
Sign in to follow this  

How to get the context menu after a right click on a treeview node

Recommended Posts


hi all,

I'm very new with the autoit tool and I'm trying to get the contents of a context menu after a ControlClick on one of the nodes of a treeview. I can successfully make the right click but I cannot get the context menu. I want to be able to select one of the options of the context menu.

So far I have seen a couple of post here at the forums but none of them have worked for me.


Like this one:

'?do=embed' frameborder='0' data-embedContent>>


I've trying this for a while but with no avail. Here's my code:

#include <WinAPI.au3>
#include <GuiTreeView.au3>
#include <GuiMenu.au3>
#include <WindowsConstants.au3>
#include <GuiConstantsEx.au3>
#include <GuiListView.au3>

Local $cLv

Run("C:\Program Files\Microsoft Visual Studio 11.0\Common7\IDE\devenv.exe")
WinWaitActive("[TITLE:Start Page - Microsoft Visual Studio (Administrator)]", "", 5)
$title = "Start Page - Microsoft Visual Studio (Administrator)"
Local $hWnd = WinGetHandle($title)
$hTreeView = ControlGetHandle($hWnd, "", "[CLASS:SysTreeView32; INSTANCE:1]")
$hTMP = _GUICtrlTreeView_FindItem($hTreeView, "Data Connections", True) ; $treename = tree name if the main tree has a name.


If $hTMP Then
        _GUICtrlTreeView_Expand($hTreeView,$hTMP, True)
        $hChild = _GUICtrlTreeView_GetFirstChild($hTreeView, $hTMP)  ; first child below data connections
        _GUICtrlTreeView_SelectItem($hTreeView, $hChild)
        $cLv = $hChild

        _GUICtrlTreeView_ClickItem($hTreeView,$hChild, "right", False, 2)

        While 1
            Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE
                ;put all the misc. stuff here
            Case Else

;MouseClick("left",  )

Func _WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    #forceref $hWnd, $Msg, $wParam
    Local $tNMHDR, $hWndFrom, $iCode
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = HWnd(DllStructGetData($tNMHDR, "hWndFrom"))
    $iCode = DllStructGetData($tNMHDR, "Code")
    ConsoleWrite("Right click 1" & @CR)

    Local $IDFrom = DllStructGetData($tNMHDR, "IDFrom")

    Switch $IDFrom
        Case $cLv
            Switch $iCode
                Case $NM_RCLICK ; determine if right click on an item
                    ConsoleWrite("Right click" & @CR)
                    Local $tInfox = DllStructCreate($tagNMITEMACTIVATE, $lParam)
                    If @error Then Return $GUI_RUNDEFMSG
                    Local $Item = DllStructGetData($tInfox, "Index")
                    If @error Or $Item = -1 Then Return $GUI_RUNDEFMSG
                    Local $tTest = DllStructCreate($tagLVHITTESTINFO)
                    DllStructSetData($tTest, "X", DllStructGetData($tInfox, "X"))
                    DllStructSetData($tTest, "Y", DllStructGetData($tInfox, "Y"))
                    Local $iRet = GUICtrlSendMsg($IDFrom, $LVM_HITTEST, 0, DllStructGetPtr($tTest))
                    If @error Or $iRet = -1 Then Return $GUI_RUNDEFMSG ; -1 = not on lv item, otherwise returns index
                    Switch DllStructGetData($tTest, "Flags")
                        Case $LVHT_ONITEMICON, $LVHT_ONITEMLABEL, $LVHT_ONITEM ;hit was on item icon or 1st column item or subitem
                            $fSysMenu = True
EndFunc   ;==>_WM_NOTIFY

This works fine until I send the right click on one of the nodes. But I never catch the right click on the control.

Hope someone can give a hint on this.

Thanks in advance!


Share this post

Link to post
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
Sign in to follow this  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.