Jump to content

Recommended Posts

Posted

You guys are awesome. I am really brain dead right now but looking over your ideas it all seems to be pointing into the right direction.

Thanks.

Posted

iAmNewbe,

Here is a little interactive example. May be this can help you. Right click to add siblings and children.

#include <GUIConstants.au3>
#include <WindowsConstants.au3>
#include <GuiTreeView.au3>
Opt( "MustDeclareVars", 1 )
MainProgram()
Func MainProgram()
; Create GUI
Local $hGui = GUICreate( "TreeView Control", 400, 300, 600, 300, BitOR( $GUI_SS_DEFAULT_GUI, $WS_MAXIMIZEBOX, $WS_SIZEBOX ) )
; Create TV
Local $iBorderWidth = 4, $aPos = WinGetClientSize( $hGui )
Local $idTV = GUICtrlCreateTreeView( $iBorderWidth, $iBorderWidth, $aPos[0]-2*$iBorderWidth, $aPos[1]-2*$iBorderWidth, -1, $WS_EX_CLIENTEDGE )
Local $hTV = ControlGetHandle( $hGui, "", $idTV )
; Add root
Local $iItem = 0, $hItem = _GUICtrlTreeView_Add( $hTV, 0, $iItem )
_GUICtrlTreeView_SelectItem( $hTV, $hItem )
$iItem += 1
; Context menu
Local $cmTV = GUICtrlCreateContextMenu( $idTV )
Local $cmTV0 = GUICtrlCreateMenuItem( "Add sibling before", $cmTV )
Local $cmTV1 = GUICtrlCreateMenuItem( "Add sibling after", $cmTV )
Local $cmTV2 = GUICtrlCreateMenuItem( "Add child", $cmTV )
GUISetState()
While 1
  Local $msg = GUIGetMsg()
  Switch $msg
   Case $GUI_EVENT_CLOSE
    ExitLoop
   Case $cmTV0
    ; Add sibling before
    $hItem = _GUICtrlTreeView_GetSelection( $hTV )
    Local $hParent = _GUICtrlTreeView_GetParentHandle( $hTV, $hItem )
    Local $hPrev = _GUICtrlTreeView_GetPrevSibling( $hTV, $hItem )
    If $hPrev = 0 Then
      _GUICtrlTreeView_AddFirst( $hTV, $hItem, $iItem )
    Else
      _GUICtrlTreeView_InsertItem( $hTV, $iItem, $hParent, $hPrev )
    EndIf
    $iItem += 1
   Case $cmTV1
    ; Add sibling after
    $hItem = _GUICtrlTreeView_GetSelection( $hTV )
    Local $hParent = _GUICtrlTreeView_GetParentHandle( $hTV, $hItem )
    _GUICtrlTreeView_InsertItem( $hTV, $iItem, $hParent, $hItem )
    $iItem += 1
   Case $cmTV2
    ; Add child
    $hItem = _GUICtrlTreeView_GetSelection( $hTV )
    _GUICtrlTreeView_AddChild( $hTV, $hItem, $iItem )
    _GUICtrlTreeView_Expand( $hTV, $hItem )
    $iItem += 1
  EndSwitch
WEnd
GUIDelete( $hGui )
Exit
EndFunc

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
  • Recently Browsing   0 members

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