Jump to content

Tree item double click to open another file?


Recommended Posts

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

$Form1 = GUICreate("I'm Too Lazy to Type", 317, 205, 266, 137, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Options")
$MenuItem4 = GUICtrlCreateMenuItem("Always on Top", $MenuItem2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetBkColor(0xC8C8C8)
$TreeView1 = GUICtrlCreateTreeView(10, 12, 297, 161, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_BORDER))
$TreeView1_0 = GUICtrlCreateTreeViewItem("CHI", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Broken desktop/WOW", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Citrix", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("Launching errors", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Website workflow", $TreeView1_5)
$TreeView1_7 = GUICtrlCreateTreeViewItem("TRUM", $TreeView1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_7)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_7)
GUISetState(@SW_SHOW)


While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

How would I insert a code where if the "Broken desktop/WOW" item is double clicked, then it will open an external program?  Would I use an "If, Then" statement there?  I've been searching everywhere but cannot understand a lot of what I am finding (newbie here..).

Link to comment
Share on other sites

Here's a start

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>

$Form1 = GUICreate("I'm Too Lazy to Type", 317, 205, 266, 137, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Options")
$MenuItem4 = GUICtrlCreateMenuItem("Always on Top", $MenuItem2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetBkColor(0xC8C8C8)
$TreeView1 = GUICtrlCreateTreeView(10, 12, 297, 161, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_BORDER))
$TreeView1_0 = GUICtrlCreateTreeViewItem("CHI", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Broken desktop/WOW", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Citrix", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("Launching errors", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Website workflow", $TreeView1_5)
$TreeView1_7 = GUICtrlCreateTreeViewItem("TRUM", $TreeView1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_7)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_7)
GUISetState(@SW_SHOW)
Local $PlaylistsWindow, $SearchCursorInfo, $GetLTLV

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
    ;=============================================================================
    $PlaylistsWindow = WinGetState($Form1)
        If BitAND($PlaylistsWindow, 8) Then
            $SearchCursorInfo = GUIGetCursorInfo($Form1)
            If $SearchCursorInfo[4] = $TreeView1 Then
                If _IsPressed("01") Then
                    If _IsPressed("01") Then
                        ConsoleWrite(_GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)) &' - '&@MSEC&@CRLF)
                    EndIf
                EndIf
            EndIf
        EndIf
    ;=============================================================================
WEnd

 

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Wow, thank you sir. I didn't know it was going to be that complicated lol. Let's say I wanted to open notepad, where would I insert that within the code you gave me? I'm a newbie.   

Also, if I wanted to open an external program if I clicked on another teeeview item, would I basically have to copy your code each time I wanted to do the same thing, but by clicking on different words?

Link to comment
Share on other sites

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <TrayConstants.au3>
;=============================================================================
Opt("TrayIconDebug", 1)
Opt("TrayMenuMode", 1)
Opt("TrayIconHide", 0)
Opt("GUIOnEventMode", 1)
Opt("TrayAutoPause", 0)
Opt("TrayOnEventMode", 1)
;=============================================================================
$Form1 = GUICreate("I'm Too Lazy to Type", 317, 205, 266, 137, -1, BitOR($WS_EX_TOPMOST,$WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Options")
$MenuItem4 = GUICtrlCreateMenuItem("Always on Top", $MenuItem2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetBkColor(0xC8C8C8)
;=============================================================================
$TreeView1 = GUICtrlCreateTreeView(10, 12, 297, 161, BitOR($GUI_SS_DEFAULT_TREEVIEW,$WS_BORDER))
$TreeView1_0 = GUICtrlCreateTreeViewItem("CHI", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Broken desktop/WOW", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Citrix", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("Launching errors", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Website workflow", $TreeView1_5)
$TreeView1_7 = GUICtrlCreateTreeViewItem("TRUM", $TreeView1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_7)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_7)
$TreeView1_10 = GUICtrlCreateTreeViewItem("notepad.exe", $TreeView1_7)
$TreeView1_11 = GUICtrlCreateTreeViewItem("External", $TreeView1_7)
;=============================================================================
Local $ExitItem = TrayCreateItem("Close App")
TrayItemSetOnEvent(-1, "Quit")
GUISetOnEvent($GUI_EVENT_CLOSE, "Quit")
GUISetState(@SW_SHOW)
Local $PlaylistsWindow, $SearchCursorInfo, $GetLTLV
;=============================================================================
While 1
    Sleep(100)
    ;=============================================================================
    $PlaylistsWindow = WinGetState($Form1)
        If BitAND($PlaylistsWindow, 8) Then
            $SearchCursorInfo = GUIGetCursorInfo($Form1)
            If $SearchCursorInfo[4] = $TreeView1 Then
                If _IsPressed("01") Then
                    Sleep(10)
                    If _IsPressed("01") Then
                        If _GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)) = "External" Then
                            Local $FileOpen = FileOpenDialog('External Application', @ScriptDir, "All (*.*)")
                            If Not @error then
                            ShellExecute($FileOpen)
                            EndIf
                        Else
                        ConsoleWrite(_GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)) &' - '&@MSEC&@CRLF)
                        Run(_GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)))
                        EndIf
                    EndIf
                EndIf
            EndIf
        EndIf
    ;=============================================================================
WEnd
;=============================================================================
Func Quit()
    TrayItemSetState($ExitItem, $TRAY_UNCHECKED)
    Exit
EndFunc
;=============================================================================

Didn't really need to be complicated, but i decided to add some code to make sure it only acts if the window is active so it doesn't detect the clicks from behind other windows. The opening of the items is jerky, sometimes takes 2 clicks, other times only one. No time to figure out why atm.

Edited by careca
Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

It opens on mine, it should open there if you can open it by writing notepad.exe to the run.

It serves as an example, you can adapt for whatever.

For instance, you may have in the tree a name for an application, say "12345"

And then in the code you can have a line such as

If _GUICtrlTreeView_GetText($TreeView1, GUICtrlRead($TreeView1)) = "12345" Then
ShellExecute('C:\applicationpath\app.exe')

Know what i mean?

Or have the name of the application right in the tree, for instance the notepad.exe or just notepad, depends on the computer, if it's a common application, you can replace it by the whole path for the application.

Spoiler

Renamer - Rename files and folders, remove portions of text from the filename etc.

GPO Tool - Export/Import Group policy settings.

MirrorDir - Synchronize/Backup/Mirror Folders

BeatsPlayer - Music player.

Params Tool - Right click an exe to see it's parameters or execute them.

String Trigger - Triggers pasting text or applications or internet links on specific strings.

Inconspicuous - Hide files in plain sight, not fully encrypted.

Regedit Control - Registry browsing history, quickly jump into any saved key.

Time4Shutdown - Write the time for shutdown in minutes.

Power Profiles Tool - Set a profile as active, delete, duplicate, export and import.

Finished Task Shutdown - Shuts down pc when specified window/Wndl/process closes.

NetworkSpeedShutdown - Shuts down pc if download speed goes under "X" Kb/s.

IUIAutomation - Topic with framework and examples

Au3Record.exe

Link to comment
Share on other sites

Okay, so I did get it to open notepad.  Only thing is, after I click "CHI" to expand the tree and I click on Hardware, it will open notepad.  It also opens notepad on all the extended trees also rather then just the "broken desktop/WOW" one.  Sorry man, I'm new to a lot of this stuff.  I used Koda to create the Tree!

 

Edit: Scratch that, I copied it wrong lol.

Edited by bballjoe12
Link to comment
Share on other sites

Here a way by using events management,

(thanks goes to @Danyfirex, see here https://www.autoitscript.com/forum/topic/163672-how-to-merge-treeview-event-handling-from-2-examples-in-1/?do=findComment&comment=1193119)

I've added a statusBar at bottom of your gui to show what happens. On the left of the StatusBar there is the currently selected full tree path, while on the right is shown the action performed (click or doubbleclick) and on which item.
Also, on the console is shown when an item is expanded or closed by clicking on +/-

 

To take actions based on the doubbleclicked item, just add more "Case" in the Switch $sCurrentTreeItem.

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GuiStatusBar.au3> ; <---
Global $sTreeViewEvernt = "" ; <---

$Form1 = GUICreate("I'm Too Lazy to Type", 317, 225, 266, 137, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Options")
$MenuItem4 = GUICtrlCreateMenuItem("Always on Top", $MenuItem2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetBkColor(0xC8C8C8)
$TreeView1 = GUICtrlCreateTreeView(10, 12, 297, 161, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER))
$TreeView1_0 = GUICtrlCreateTreeViewItem("CHI", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Broken desktop/WOW", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Citrix", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("Launching errors", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Website workflow", $TreeView1_5)
$TreeView1_7 = GUICtrlCreateTreeViewItem("TRUM", $TreeView1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_7)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_7)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1) ; <---
_GUICtrlStatusBar_SetParts($StatusBar1, 2, 170)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ; <---
Local $PlaylistsWindow, $SearchCursorInfo, $GetLTLV

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $sTreeViewEvernt <> "" Then ; check if there was on click or doubbleclick on the TreeView

        ; currently selections
        $sCurrentTreePath = _GUICtrlTreeView_GetTree($TreeView1, _GUICtrlTreeView_GetSelection($TreeView1)) ; full path
        $sCurrentTreeItem = _GUICtrlTreeView_GetText($TreeView1, _GUICtrlTreeView_GetSelection($TreeView1)) ; single item

        If _GUICtrlStatusBar_GetText($StatusBar1, 0) <> $sCurrentTreePath Then
            _GUICtrlStatusBar_SetText($StatusBar1, $sCurrentTreePath) ; show the selected Tree Path on the right of statusbar
        EndIf

        Switch $sTreeViewEvernt
            Case "Click"
                _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt & " on " & $sCurrentTreeItem, 1)
                $sTreeViewEvernt = "" ; reset my event status flag variable


            Case "DblClick"
                _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt & " on " & $sCurrentTreeItem, 1)
                $sTreeViewEvernt = "" ; reset my event status flag variable

                ; Perform Here your action OnDoubbleClick
                
                ; set here your actions based on doubbleclicked item
                ; --------------------------------------------------
                Switch $sCurrentTreeItem ; the selected item
                    Case "Broken desktop/WOW"
                        ShellExecute("notepad.exe") ; just as an exeample run notepad

                        ; add other cases here

                EndSwitch


        EndSwitch
    EndIf

WEnd

Func WM_Notify_Events($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID
    Select
        Case $wParam = $TreeView1 ; was event fired by $hTree ?
            ; Create NMTREEVIEW structure
            Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
                    "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
                    "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
                    "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
                    "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
                    "struct;long PointX;long PointY;endstruct", $lParam)

            If @error Then Return

            Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom") ;  <---< handle of the TreeView
            Local $iEvent = DllStructGetData($tStruct, "Code") ;         <---< Type of event

            Switch $iEvent ; https://msdn.microsoft.com/en-us/library/windows/desktop/ff486107(v=vs.85).aspx

                Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA ; click on */- expand/close node
                    Local $fExpanded = DllStructGetData($tStruct, "Action") ;   <---< 1 = node closed, 2 = node expanded
                    Local $hNewItem = DllStructGetData($tStruct, "NewhItem") ;  <---< Handle to the Item on the right of the +/- sign
                    ConsoleWrite("DEbug: " & _GUICtrlTreeView_GetText($hWndFrom, $hNewItem) & " : " & (($fExpanded = 1) ? "node closed" : "node expanded") & @CRLF)
                    _GUICtrlTreeView_SelectItem($hWndFrom, $hNewItem) ; set focus to expanded/closed item

                Case $NM_CLICK
                    ; ConsoleWrite("Debug: Click" & @CRLF)
                    $sTreeViewEvernt = "Click"
                    ; _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt, 1)


                Case $NM_DBLCLK
                    ; ConsoleWrite("Debug: DoubbleClick" & @CRLF)
                    $sTreeViewEvernt = "DblClick"
                    ; _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt, 1)

            EndSwitch
            $tStruct = 0
            Return
    EndSelect
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_Notify_Events

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

1 hour ago, Chimp said:

Here a way by using events management,

(thanks goes to @Danyfirex, see here https://www.autoitscript.com/forum/topic/163672-how-to-merge-treeview-event-handling-from-2-examples-in-1/?do=findComment&comment=1193119)

I've added a statusBar at bottom of your gui to show what happens. On the left of the StatusBar there is the currently selected full tree path, while on the right is shown the action performed (click or doubbleclick) and on which item.
Also, on the console is shown when an item is expanded or closed by clicking on +/-

 

To take actions based on the doubbleclicked item, just add more "Case" in the Switch $sCurrentTreeItem.

#include <GUIConstantsEx.au3>
#include <TreeViewConstants.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <GuiStatusBar.au3> ; <---
Global $sTreeViewEvernt = "" ; <---

$Form1 = GUICreate("I'm Too Lazy to Type", 317, 225, 266, 137, -1, BitOR($WS_EX_TOPMOST, $WS_EX_WINDOWEDGE))
$MenuItem1 = GUICtrlCreateMenu("File")
$MenuItem3 = GUICtrlCreateMenuItem("Exit", $MenuItem1)
$MenuItem2 = GUICtrlCreateMenu("Options")
$MenuItem4 = GUICtrlCreateMenuItem("Always on Top", $MenuItem2)
GUICtrlSetState(-1, $GUI_CHECKED)
GUISetBkColor(0xC8C8C8)
$TreeView1 = GUICtrlCreateTreeView(10, 12, 297, 161, BitOR($GUI_SS_DEFAULT_TREEVIEW, $WS_BORDER))
$TreeView1_0 = GUICtrlCreateTreeViewItem("CHI", $TreeView1)
$TreeView1_1 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_0)
$TreeView1_2 = GUICtrlCreateTreeViewItem("Broken desktop/WOW", $TreeView1_1)
$TreeView1_3 = GUICtrlCreateTreeViewItem("Citrix", $TreeView1_0)
$TreeView1_4 = GUICtrlCreateTreeViewItem("Launching errors", $TreeView1_3)
$TreeView1_5 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_0)
$TreeView1_6 = GUICtrlCreateTreeViewItem("Website workflow", $TreeView1_5)
$TreeView1_7 = GUICtrlCreateTreeViewItem("TRUM", $TreeView1)
$TreeView1_8 = GUICtrlCreateTreeViewItem("Hardware", $TreeView1_7)
$TreeView1_9 = GUICtrlCreateTreeViewItem("Internet/Websites", $TreeView1_7)
$StatusBar1 = _GUICtrlStatusBar_Create($Form1) ; <---
_GUICtrlStatusBar_SetParts($StatusBar1, 2, 170)
GUISetState(@SW_SHOW)
GUIRegisterMsg($WM_NOTIFY, "WM_Notify_Events") ; <---
Local $PlaylistsWindow, $SearchCursorInfo, $GetLTLV

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch

    If $sTreeViewEvernt <> "" Then ; check if there was on click or doubbleclick on the TreeView

        ; currently selections
        $sCurrentTreePath = _GUICtrlTreeView_GetTree($TreeView1, _GUICtrlTreeView_GetSelection($TreeView1)) ; full path
        $sCurrentTreeItem = _GUICtrlTreeView_GetText($TreeView1, _GUICtrlTreeView_GetSelection($TreeView1)) ; single item

        If _GUICtrlStatusBar_GetText($StatusBar1, 0) <> $sCurrentTreePath Then
            _GUICtrlStatusBar_SetText($StatusBar1, $sCurrentTreePath) ; show the selected Tree Path on the right of statusbar
        EndIf

        Switch $sTreeViewEvernt
            Case "Click"
                _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt & " on " & $sCurrentTreeItem, 1)
                $sTreeViewEvernt = "" ; reset my event status flag variable


            Case "DblClick"
                _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt & " on " & $sCurrentTreeItem, 1)
                $sTreeViewEvernt = "" ; reset my event status flag variable

                ; Perform Here your action OnDoubbleClick
                
                ; set here your actions based on doubbleclicked item
                ; --------------------------------------------------
                Switch $sCurrentTreeItem ; the selected item
                    Case "Broken desktop/WOW"
                        ShellExecute("notepad.exe") ; just as an exeample run notepad

                        ; add other cases here

                EndSwitch


        EndSwitch
    EndIf

WEnd

Func WM_Notify_Events($hWndGUI, $iMsgID, $wParam, $lParam)
    #forceref $hWndGUI, $iMsgID
    Select
        Case $wParam = $TreeView1 ; was event fired by $hTree ?
            ; Create NMTREEVIEW structure
            Local $tStruct = DllStructCreate("struct;hwnd hWndFrom;uint_ptr IDFrom;INT Code;endstruct;" & _
                    "uint Action;struct;uint OldMask;handle OldhItem;uint OldState;uint OldStateMask;" & _
                    "ptr OldText;int OldTextMax;int OldImage;int OldSelectedImage;int OldChildren;lparam OldParam;endstruct;" & _
                    "struct;uint NewMask;handle NewhItem;uint NewState;uint NewStateMask;" & _
                    "ptr NewText;int NewTextMax;int NewImage;int NewSelectedImage;int NewChildren;lparam NewParam;endstruct;" & _
                    "struct;long PointX;long PointY;endstruct", $lParam)

            If @error Then Return

            Local $hWndFrom = DllStructGetData($tStruct, "hWndFrom") ;  <---< handle of the TreeView
            Local $iEvent = DllStructGetData($tStruct, "Code") ;         <---< Type of event

            Switch $iEvent ; https://msdn.microsoft.com/en-us/library/windows/desktop/ff486107(v=vs.85).aspx

                Case $TVN_ITEMEXPANDEDW, $TVN_ITEMEXPANDEDA ; click on */- expand/close node
                    Local $fExpanded = DllStructGetData($tStruct, "Action") ;   <---< 1 = node closed, 2 = node expanded
                    Local $hNewItem = DllStructGetData($tStruct, "NewhItem") ;  <---< Handle to the Item on the right of the +/- sign
                    ConsoleWrite("DEbug: " & _GUICtrlTreeView_GetText($hWndFrom, $hNewItem) & " : " & (($fExpanded = 1) ? "node closed" : "node expanded") & @CRLF)
                    _GUICtrlTreeView_SelectItem($hWndFrom, $hNewItem) ; set focus to expanded/closed item

                Case $NM_CLICK
                    ; ConsoleWrite("Debug: Click" & @CRLF)
                    $sTreeViewEvernt = "Click"
                    ; _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt, 1)


                Case $NM_DBLCLK
                    ; ConsoleWrite("Debug: DoubbleClick" & @CRLF)
                    $sTreeViewEvernt = "DblClick"
                    ; _GUICtrlStatusBar_SetText($StatusBar1, $sTreeViewEvernt, 1)

            EndSwitch
            $tStruct = 0
            Return
    EndSelect
    Return $GUI_RUNDEFMSG

EndFunc   ;==>WM_Notify_Events

This works perfectly! Now, I just have to figure out how to edit the other options when I need to add more! lol

 

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...