Jump to content

How to get the item I right clicked in a TreeView


Recommended Posts

I been working on a AD tree program and have run in to a problem, I cannot get the text from the selected Treeview item when I left click on the Context Menu item.

See Code

Thanks in Adance!

#include <Misc.au3>
#include <GUIConstants.au3>
#Include <GuiTreeView.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <AD.au3>
#include <array.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
Global $vLvl1, $vLvl2, $vLvl3, $vLvl4, $SelectedValue
$mainform = GUICreate("Organizational Tree", 600, 900)
$tviewPI = GUICtrlCreateTreeView(10, 10, 580, 880, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes), $WS_EX_CLIENTEDGE)
$tviewPICon = GUICtrlCreateContextMenu($tviewPI)
$tviewPIConGetWks = GUICtrlCreateMenuItem("Get workstations", $tviewPICon)
$tviewPIConCheckReg = GUICtrlCreateMenuItem("Check Registry", $tviewPICon)
$tviewPIConCheckfiles = GUICtrlCreateMenuItem("Check for Files", $tviewPICon)
$tviewPIConGetProcessList = GUICtrlCreateMenuItem("Process List", $tviewPICon)
$tviewPIConGetUserProfiles = GUICtrlCreateMenuItem("Get User Profiles Names", $tviewPICon)
$MainMenu = GUICtrlCreateTreeViewItem("Workstation Organizational Units", $tviewPI)
;$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

;_AD_Open()
;$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
;_ArrayDisplay($aOUs)
;_AD_Close()

;Test OU GRoup
$TestParentOU=GUICtrlCreateTreeViewItem("Test OU Group",$MainMenu)
;$tstou = _ArrayFindAll($aOUs,"OU=Test Workstation",0,0,0,1,1)
;For $i = 1 To UBound($tstou,1) - 1
$TestChildOU1=GUICtrlCreateTreeViewItem("Level 1 OU",$TestParentOU)
$TestChildOU2=GUICtrlCreateTreeViewItem("Level 2 OU",$TestChildOU1)
$TestChildOU3=GUICtrlCreateTreeViewItem("Level 3 OU",$TestChildOU2)
;$TestChildOU4=GUICtrlCreateTreeViewItem("Level 4 OU",$TestChildOU3)
;Next

GUICtrlSetColor(-1, 0x0000C0)
GUICtrlSetState($MainMenu, BitOR($GUI_EXPAND, $GUI_DEFBUTTON))
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
        Case $Msg = $tviewPIConGetWks
            MsgBox(0,"","Check for Workstations")
        Case $Msg = $tviewPIConCheckReg
            MsgBox(0,"","Check Registry")
    EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam) ; Barrowed this works great
;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    ;$hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $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_RCLICK
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                Global $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $var = 0

    $A = _GUICtrlTreeView_GetItemHandle($tviewPI, $TVhItem)
    $B = _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem)
    $C = _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem))
    $D = _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem)))

    If $D = 0 And $C = 0 And $B = 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl2 = ""
    $vLvl3 = ""
    $vLvl4 = ""
    ;$SelectedValue = "A:"&$vLvl1

    ElseIf $D = 0 And $C = 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl3 = ""
    $vLvl4 = ""
    ;$SelectedValue = "B:"&$vLvl2

    ElseIf $D = 0 And $C <> 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $C)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl3 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl4 = ""
    ;$SelectedValue = "C:"&$vLvl3

    ElseIf $D <> 0 And $C <> 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $D)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $C)
    $vLvl3 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl4 = _GUICtrlTreeView_GetText($tviewPI, $A)
    ;$SelectedValue = "D:"&$vLvl4

    EndIf

    ToolTip ("$A: " & $A & @CRLF & "$B: " & $B & @CRLF & "$C: " & $C & @CRLF & "$D: " & $D & @CRLF & @CRLF & $vLvl1 & @CRLF & $vLvl2 & @CRLF & $vLvl3 & @CRLF & $vLvl4, 0, 0)

                    EndSwitch
            EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func GetWorkstations($getObject)
    Global $workstationnames = _AD_GetObjectsInOU($getObject, "(&(objectcategory=computer)(objectclass=computer))", 2, "name")
    _ArrayDisplay($workstationnames)
EndFunc
Func _GetHitString($iResult)
    If $iResult = 0 Then
        Return "No Item in Hit area"
    Else
        Return "Item Handle: " & $iResult
    EndIf
EndFunc   ;==>_GetHitString
Link to comment
Share on other sites

Mixing native AutoIt controls with the UDF functions often results in weirdness and pain. If you intend to manage it with the GuiTreeView.au3 UDF, you should create it with _GuiCtrlTreeView_Create() and add the items with the UDF functions also.

;)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

Mixing native AutoIt controls with the UDF functions often results in weirdness and pain. If you intend to manage it with the GuiTreeView.au3 UDF, you should create it with _GuiCtrlTreeView_Create() and add the items with the UDF functions also.

;)

Okay I will give it a go then, Thanks!
Link to comment
Share on other sites

well after converting everything to GuiCtrlTreeView_Create, _GUICtrlTreeView_Add, and _GUICtrlTreeView_AddChild I can no long use teh ContextMenu nor the GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY") functions.

#include <Misc.au3>
#include <GUIConstants.au3>
#Include <GuiTreeView.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <AD.au3>
#include <array.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
Global $vLvl1, $vLvl2, $vLvl3, $vLvl4, $SelectedValue
$mainform = GUICreate("Organizational Tree", 600, 900)
$tviewPI = _GuiCtrlTreeView_Create($mainform,10, 10, 580, 880, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes), $WS_EX_CLIENTEDGE)
$MainOU = _GUICtrlTreeView_Add($tviewPI,0,"Workstation Organizational Units")
$tviewPICon = GUICtrlCreateContextMenu($MainOU)
$tviewPIConGetWks = GUICtrlCreateMenuItem("Get workstations", $tviewPICon)
$tviewPIConCheckReg = GUICtrlCreateMenuItem("Check Registry", $tviewPICon)
$tviewPIConCheckfiles = GUICtrlCreateMenuItem("Check for Files", $tviewPICon)
$tviewPIConGetProcessList = GUICtrlCreateMenuItem("Process List", $tviewPICon)
$tviewPIConGetUserProfiles = GUICtrlCreateMenuItem("Get User Profiles Names", $tviewPICon)

;$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

;_AD_Open()
;$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
;_ArrayDisplay($aOUs)
;_AD_Close()

;Test OU GRoup
$TestParentOU=_GUICtrlTreeView_AddChild($tviewPI, $MainOU,"Test OU Group")
;$tstou = _ArrayFindAll($aOUs,"OU=Test Workstation",0,0,0,1,1)
;For $i = 1 To UBound($tstou,1) - 1
$TestChildOU1=_GUICtrlTreeView_AddChild($tviewPI,$TestParentOU,"Level 1 OU")
$TestObj1=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj1")
$TestObj2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj2")
$TestChildOU2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 2 OU")
$TestObj3=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj1")
$TestObj4=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj2")
;Next

GUICtrlSetColor(-1, 0x0000C0)
_GUICtrlTreeView_SetState($tviewPI,$MainOU,$TVIS_EXPANDPARTIAL)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)
While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
     EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    ;$hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $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_RCLICK
                    ToolTip("Test",0,0,"Testing")
                    #cs
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                Global $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $var = 0

    $A = _GUICtrlTreeView_GetItemHandle($tviewPI, $TVhItem)
    $B = _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem)
    $C = _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem))
    $D = _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, _GUICtrlTreeView_GetParentHandle($tviewPI, $TVhItem)))

    If $D = 0 And $C = 0 And $B = 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl2 = ""
    $vLvl3 = ""
    $vLvl4 = ""
    ;$SelectedValue = "A:"&$vLvl1

    ElseIf $D = 0 And $C = 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl3 = ""
    $vLvl4 = ""
    ;$SelectedValue = "B:"&$vLvl2

    ElseIf $D = 0 And $C <> 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $C)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl3 = _GUICtrlTreeView_GetText($tviewPI, $A)
    $vLvl4 = ""
    ;$SelectedValue = "C:"&$vLvl3

    ElseIf $D <> 0 And $C <> 0 And $B <> 0 And $A <> 0 Then
    $vLvl1 = _GUICtrlTreeView_GetText($tviewPI, $D)
    $vLvl2 = _GUICtrlTreeView_GetText($tviewPI, $C)
    $vLvl3 = _GUICtrlTreeView_GetText($tviewPI, $B)
    $vLvl4 = _GUICtrlTreeView_GetText($tviewPI, $A)
    ;$SelectedValue = "D:"&$vLvl4

    EndIf

    ToolTip ("$A: " & $A & @CRLF & "$B: " & $B & @CRLF & "$C: " & $C & @CRLF & "$D: " & $D & @CRLF & @CRLF & $vLvl1 & @CRLF & $vLvl2 & @CRLF & $vLvl3 & @CRLF & $vLvl4, 0, 0)
#CE
                    EndSwitch
            EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func GetWorkstations($getObject)
    Global $workstationnames = _AD_GetObjectsInOU($getObject, "(&(objectcategory=computer)(objectclass=computer))", 2, "name")
    _ArrayDisplay($workstationnames)
EndFunc
Link to comment
Share on other sites

Okay I resolved one issue but created another, The question was how to get text from selected right mouse click. the new code works great for that. But I can no long create a ContextMenu to the selected item.

#include <Misc.au3>
#include <GUIConstants.au3>
#Include <GuiTreeView.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <AD.au3>
#include <array.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>


;Global $vLvl1, $vLvl2, $vLvl3, $vLvl4, $SelectedValue

$mainform = GUICreate("Organizational Tree", 600, 900)
$tviewPI = _GuiCtrlTreeView_Create($mainform,10, 10, 580, 880, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes), $WS_EX_CLIENTEDGE)
$MainOU = _GUICtrlTreeView_Add($tviewPI,0,"Workstation Organizational Units")
$tviewPICon = GUICtrlCreateContextMenu($MainOU)
$tviewPIConGetWks = GUICtrlCreateMenuItem("Get workstations", $tviewPICon)
$tviewPIConCheckReg = GUICtrlCreateMenuItem("Check Registry", $tviewPICon)
$tviewPIConCheckfiles = GUICtrlCreateMenuItem("Check for Files", $tviewPICon)
$tviewPIConGetProcessList = GUICtrlCreateMenuItem("Process List", $tviewPICon)
$tviewPIConGetUserProfiles = GUICtrlCreateMenuItem("Get User Profiles Names", $tviewPICon)

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

;_AD_Open()
;$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
;_ArrayDisplay($aOUs)
;_AD_Close()

;Test OU GRoup
$TestParentOU=_GUICtrlTreeView_AddChild($tviewPI, $MainOU,"Test OU Group")
;$tstou = _ArrayFindAll($aOUs,"OU=Test Workstation",0,0,0,1,1)
;For $i = 1 To UBound($tstou,1) - 1
$TestChildOU1=_GUICtrlTreeView_AddChild($tviewPI,$TestParentOU,"Level 1 OU")
$TestObj1=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj1")
$TestObj2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj2")
$TestChildOU2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 2 OU")
$TestObj3=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj1")
$TestObj4=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj2")
;Next

GUICtrlSetColor(-1, 0x0000C0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUISetState(@SW_SHOW)

While 1
    $Msg = GUIGetMsg()
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
     EndSelect
WEnd

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    $hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $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_RCLICK

                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $TVtext = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)
                ToolTip($TVtext,0.0)
                EndSwitch
            EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func GetWorkstations($getObject)
    Global $workstationnames = _AD_GetObjectsInOU($getObject, "(&(objectcategory=computer)(objectclass=computer))", 2, "name")
    _ArrayDisplay($workstationnames)
EndFunc
Link to comment
Share on other sites

I added the Pupup code but having issues with getting the select popup menu selection.

#include <Misc.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#Include <GuiTreeView.au3>
#include <TreeviewConstants.au3>
#include <WindowsConstants.au3>
#Include <WinAPI.au3>
#include <AD.au3>
#include <array.au3>
#include <StaticConstants.au3>
#Include <WinAPI.au3>
#Include <GuiMenu.au3>

Global Enum $idOpen = 1000, $idSave, $idInfo


;Global $vLvl1, $vLvl2, $vLvl3, $vLvl4, $SelectedValue

$mainform = GUICreate("Organizational Tree", 600, 900)
$tviewPI = _GuiCtrlTreeView_Create($mainform,10, 10, 250, 880, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS, $TVS_Checkboxes), $WS_EX_CLIENTEDGE)
$MainOU = _GUICtrlTreeView_Add($tviewPI,0,"Workstation Organizational Units")

$Debug_TV = False ; Check ClassName being passed to functions, set to True and use a handle to another control to see it work

;_AD_Open()
;$aOUs = _AD_GetAllOUs("OU=THR Workstations,DC=txhealth,DC=org")
;_ArrayDisplay($aOUs)
;_AD_Close()

;Test OU GRoup
$TestParentOU=_GUICtrlTreeView_AddChild($tviewPI, $tviewPI,"Test OU Group")
;$tstou = _ArrayFindAll($aOUs,"OU=Test Workstation",0,0,0,1,1)
;For $i = 1 To UBound($tstou,1) - 1
$TestChildOU1=_GUICtrlTreeView_AddChild($tviewPI,$TestParentOU,"Level 1 OU")
$TestObj1=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj1")
$TestObj2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 1 Obj2")
$TestChildOU2=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU1,"Level 2 OU")
$TestObj3=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj1")
$TestObj4=_GUICtrlTreeView_AddChild($tviewPI,$TestChildOU2,"Level 2 Obj2")
;Next

GUICtrlSetColor(-1, 0x0000C0)
GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")
GUIRegisterMsg($WM_COMMAND, "WM_COMMAND")
    GUIRegisterMsg($WM_CONTEXTMENU, "WM_CONTEXTMENU")
GUISetState(@SW_SHOW)
_Main()
Func _Main()
    Local $mainform
    ;Register message handlers

    While 1
    $Msg = GUIGetMsg()
    Sleep(1000)
    ToolTip($Msg,-1,-1)
    Select
        Case $Msg = $GUI_EVENT_CLOSE
            Exit
    EndSelect
    WEnd
EndFunc   ;==>_Main

Func WM_NOTIFY($hWnd, $iMsg, $iwParam, $ilParam)
    ;~ ConsoleWrite('@@ (' & @ScriptLineNumber & ') :(' & @MIN & ':' & @SEC & ') WM_NOTIFY()' & @CR) ;### Function Trace
    #forceref $hWnd, $iMsg, $iwParam
    Local $hWndFrom, $iIDFrom, $iCode, $tNMHDR, $hWndTreeView, $tInfo
    $hWndTreeView = $tviewPI
    If Not IsHWnd($tviewPI) Then $hWndTreeView = GUICtrlGetHandle($tviewPI)

    $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
                $tInfo = DllStructCreate($tagNMITEMACTIVATE, $ilParam)
                Local $tPoint, $tTVHEx, $TVhItem, $mX, $mY
                $tPoint = _WinAPI_GetMousePos(True, $tviewPI)
                $mX = DllStructGetData($tPoint, "X")
                $mY = DllStructGetData($tPoint, "Y")
                $TVhItem = _GUICtrlTreeView_HitTestItem($tviewPI, $mX, $mY)
                _GUICtrlTreeView_SetFocused($tviewPI, $TVhItem)
                $TVtext = _GUICtrlTreeView_GetText($tviewPI,$TVhItem)
                ToolTip("HnWd"&" : "&$TVhItem&" "&"Text found on the handle"&" : "&$TVtext,0.0)
            EndSwitch
        EndSwitch
    Return $GUI_RUNDEFMSG
EndFunc ;==>WM_NOTIFY

Func GetWorkstations($getObject)
    Global $workstationnames = _AD_GetObjectsInOU($getObject, "(&(objectcategory=computer)(objectclass=computer))", 2, "name")
    _ArrayDisplay($workstationnames)
EndFunc

; Show at the given coordinates (x, y) the popup menu (hMenu) which belongs to a given GUI window (hWnd)

Func WM_COMMAND($hWnd, $iMsg, $iwParam, $ilParam)
    ToolTip($hWnd&":"&$iMsg&":"&$iwParam&":"&$ilParam,0,0)
    Switch $iwParam
        Case $idOpen
            _WinAPI_ShowMsg ("Open")
        Case $idSave
            _WinAPI_ShowMsg ("Save")
        Case $idInfo
            _WinAPI_ShowMsg ("Info")
    EndSwitch
EndFunc   ;==>WM_COMMAND

; Handle WM_CONTEXTMENU messages
Func WM_CONTEXTMENU($hWnd, $iMsg, $iwParam, $ilParam)
    Local $hMenu

    $hMenu = _GUICtrlMenu_CreatePopup ()
    _GUICtrlMenu_InsertMenuItem ($hMenu, 0, "Open", $idOpen)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 1, "Save", $idSave)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "", 0)
    _GUICtrlMenu_InsertMenuItem ($hMenu, 3, "Info", $idInfo)
    _GUICtrlMenu_TrackPopupMenu ($hMenu, $iwParam)
    _GUICtrlMenu_DestroyMenu ($hMenu)
    Return True
EndFunc   ;==>WM_CONTEXTMENU
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...