Jump to content

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)
Sleep(2000)
$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.

GUIRegisterMsg($WM_NOTIFY, "_WM_NOTIFY")
GUISetState(@SW_SHOW)

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

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

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

            EndSwitch
        WEnd
;MouseClick("left",  )
Endif


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
                    EndSwitch
            EndSwitch
    EndSwitch
    Return $GUI_RUNDEFMSG
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!

 

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...