Jump to content

mainloop handling for tree created with _GUICtrlTreeView_Create command


BeVa
 Share

Recommended Posts

Hello All,

I am looking for differences between TreeView created with:

  • GUICtrlCreateTreeView / GUICtrlCreateTreeViewItem
  • _GUICtrlTreeView_Create / _GUICtrlTreeView_Add

Mainly how to manage the Tree in mainloop.

The GUIGetMsg() doesn't work somehow

Thanks for Help

Link to comment
Share on other sites

Hello All,

I am looking for differences between TreeView created with:

  • GUICtrlCreateTreeView / GUICtrlCreateTreeViewItem
  • _GUICtrlTreeView_Create / _GUICtrlTreeView_Add

Mainly how to manage the Tree in mainloop.

The GUIGetMsg() doesn't work somehow

Thanks for Help

What exactly you need? Show your code please.

Link to comment
Share on other sites

Sample Script with running (clasical GUICtrlCreateTreeView / GUICtrlCreateTreeViewItem)

CODE
#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiEdit.au3>

#include <Array.au3>

$Form1 = GUICreate("Form1", 617, 438, 193, 117)

$Tree_test = GUICtrlCreateGroup("Tree_test", 0, 0, 633, 441)

$TreeView1 = GUICtrlCreateTreeView(16, 24, 593, 257, -1, $WS_EX_CLIENTEDGE)

$Edit1 = GUICtrlCreateEdit("", 16, 296, 593, 129)

GUICtrlSetData(-1, "Start Logging:")

GUICtrlCreateGroup("", -99, -99, 1, 1)

Dim $_tree_arr[1]

For $_i = 1 To 10

$_i_lev = GUICtrlCreateTreeViewItem($_i,$TreeView1)

For $_j = 1 To 10

$_j_lev = GUICtrlCreateTreeViewItem($_j,$_i_lev)

_ArrayAdd($_tree_arr,$_j_lev)

Next

Next

GUISetState(@SW_SHOW)

_GUICtrlEdit_InsertText($Edit1, @CRLF)

While 1

Dim $msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg >= _ArrayMin($_tree_arr,1,1) And $msg <= _ArrayMax($_tree_arr,1,1)

If _ArraySearch($_tree_arr, $msg, 1) > 0 Then

_GUICtrlEdit_InsertText($Edit1,"Leaf selected: " & $msg & @CRLF)

;~ Do Something with the Item, because the Leaf was Clicked ON

Else

;~ Do Nothing because of non Leaf Clicked ON

EndIf

EndSelect

WEnd

Sample Script with NOT running (new _GUICtrlTreeView_Create / _GUICtrlTreeView_Add)

CODE
#include <GUIConstants.au3>

#include <WindowsConstants.au3>

#Include <GuiTreeView.au3>

#Include <GuiEdit.au3>

#include <Array.au3>

$Form1 = GUICreate("Form1", 617, 438, 193, 117)

$Tree_test = GUICtrlCreateGroup("Tree_test", 0, 0, 633, 441)

$TreeView1 = _GUICtrlTreeView_Create($Form1, 16, 24, 593, 257, -1, $WS_EX_CLIENTEDGE)

$Edit1 = GUICtrlCreateEdit("", 16, 296, 593, 129)

GUICtrlSetData(-1, "Start Logging:")

GUICtrlCreateGroup("", -99, -99, 1, 1)

Dim $_tree_arr[1]

For $_i = 1 To 10

$_i_lev = _GUICtrlTreeView_Add($TreeView1, 0, $_i)

For $_j = 1 To 10

$_j_lev = _GUICtrlTreeView_AddChild($TreeView1,$_i_lev,$_j)

_ArrayAdd($_tree_arr, $_j_lev )

Next

Next

GUISetState(@SW_SHOW)

While 1

Dim $msg = GUIGetMsg()

Select

Case $msg = $GUI_EVENT_CLOSE

Exit

Case $msg >= _ArrayMin($_tree_arr,1,1) And $msg <= _ArrayMax($_tree_arr,1,1)

If _ArraySearch($_tree_arr, $msg, 1) > 0 Then

_GUICtrlEdit_InsertText($Edit1,"Leaf selected: " & $msg & @CRLF)

;~ Do Something with the Item, because the Leaf was Clicked ON

Else

;~ Do Nothing because of non Leaf Clicked ON

EndIf

EndSelect

WEnd

Samples are welcomed

Thanks

Link to comment
Share on other sites

BeVa

Try this:

#include <GuiConstantsEx.au3>
#include <GuiTreeView.au3>
#include <WindowsConstants.au3>

$Style = BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS)

$hGUI = GUICreate("Test", 300, 300)

$hTreeView = _GUICtrlTreeView_Create($hGUI, 10, 10, 280, 280)

For $i = 1 To 10
    $hItem = _GUICtrlTreeView_Add($hTreeView, 0, "Item " & $i)
    
    For $j = 1 To 10
        _GUICtrlTreeView_AddChild($hTreeView, $hItem, "Child " & $j)
    Next
Next

GUIRegisterMsg($WM_NOTIFY, "WM_NOTIFY")

GUISetState()

Do
Until GUIGetMsg() = $GUI_EVENT_CLOSE

Func WM_NOTIFY($hWnd, $Msg, $wParam, $lParam)
    Local $tNMHDR, $hWndFrom, $iCode
    
    $tNMHDR = DllStructCreate($tagNMHDR, $lParam)
    $hWndFrom = DllStructGetData($tNMHDR, "hWndFrom")
    $iCode = DllStructGetData($tNMHDR, "Code")
    
    Switch $hWndFrom
        Case $hTreeView
            Switch $iCode
                Case $NM_CLICK
                    Local $tPOINT = _WinAPI_GetMousePos(True, $hWnd)
                    Local $iX = DllStructGetData($tPOINT, "X")
                    Local $iY = DllStructGetData($tPOINT, "Y")
                    
                    Local $aPos = ControlGetPos($hGUI, "", $hTreeView)
                    
                    Local $iItem = _GUICtrlTreeView_HitTestItem($hTreeView, $iX - $aPos[0], $iY - $aPos[1])
                    ConsoleWrite("!> Clicked on " & _GUICtrlTreeView_GetText($hTreeView, $iItem) & @LF)
            EndSwitch
    EndSwitch
    
    Return $GUI_RUNDEFMSG
EndFunc
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...