Jump to content

Behavior Context Menu On Tree View


Recommended Posts

Dear developers, first of all, let me put my hands together for the people working on the AutoIt scripting language. Excellent!

Before asking a question here, I would like to take the opportunity to name the biggest program written in AutoIt: Hitman Pro. It has over 1 million bytes of source code and 1 million active users. It is therefore (I think) also the most popular tool in use written in AutoIt. I shows how easy and powerfull AutoIt can be.

Ofcourse, I am working on a new version of Hitman Pro. Currently I am adding expert features to it, using the tree view functions recently added in the latest beta.

I have several problems with the tree view. Ofcouse it would be perfect if there was a way to implement and read checkbox states of entries in my own tree views. But since the AutoIt developement team is still working on that (I've read that somewhere on this forum) I am implementing my own check and uncheck mechanism. Please look at the picture below:

Posted Image

When the first entry (HKLM\...) is selected and I right click on the second registry item (HKCU\...) all operations I implement are performed on the first entry. To put it short, right click doesn't select the entry.

This is the code I use for the tree view:

Global $tvStrider = GUICtrlCreateTreeView($X, $Y, $StriderWidth, 248 - $GUI_BUTTONDIST - 2, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)
    Global $mnuStrider = GUICtrlCreateContextMenu($tvStrider)
    Global $mnuStriderGoto = GUICtrlCreateMenuItem("Go to", $mnuStrider)
    Global $mnuStriderExclude = GUICtrlCreateMenuItem("Exclude", $mnuStrider)
    Global $mnuStriderInclude = GUICtrlCreateMenuItem("Include", $mnuStrider)
    GUICtrlSetOnEvent($mnuStriderGoto, "_btnStriderGoto")
    GUICtrlSetOnEvent($mnuStriderExclude, "_btnStriderExclude")
    GUICtrlSetOnEvent($mnuStriderInclude, "_btnStriderInclude")

Any one here with an idea? Any help is greatly appreciated.

Thanks!

Edited by markloman
Link to comment
Share on other sites

Hi Holger! i thought to put it here because tree view support is still heavily under development. My apologies if I posted it wrong (you are free to move it to the support section).

I will try to give you some more information. Ofcourse, I create items using the GUICtrlCreateTreeViewItem() function. I wrote a custom function to locate parents of childs. Please look at these code snippets.

Global $tvStrider = GUICtrlCreateTreeView($X, $Y, $StriderWidth, 248 - $GUI_BUTTONDIST - 2, BitOR($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE)

$tvStriderItem = GUICtrlCreateTreeViewItem($StriderName & " (" & $StriderProg & ")", $tvStrider)

$StriderItem = _GUICtrlTreeViewGetItem($tvStrider, $StriderName & " (" & $StriderProg & ")", $StriderItemFirst, $StriderItemLast)

$tvStriderSubItem = GUICtrlCreateTreeViewItem($StriderObject, $StriderItem)

Func _GUICtrlTreeViewGetItem($giTreeView, $giItemText, $giItemFirst, $giItemLast)
; Note: this handy function will take time when there are a lot of items in the tree view!
    Local $i, $tvItemText
    For $i = $giItemFirst To $giItemLast
        $tvItemText = _GUICtrlTreeViewGetText ($giTreeView, $i)
        If $tvItemText = $giItemText Then
            Return $i
        EndIf
    Next
    Return 0
EndFunc  ;==>_GUICtrlGetTreeViewGetItem

To speed things up a bit I added an array to keep track of the parents (names and it's identifier) that were already added to the tree view (so I don't have to use my own function _GUICtrlGetTreeViewGetItem() for this task).

But basically, when you selected a tree view entry and right click another entry, the first entry remains the selected entry. Looking at the screenshot on my first post, when you right click on an entry and select Exclude, this is what my program does:

Func _btnStriderExclude()
    Local $Text, $State
    For $i = $StriderItemFirst To $StriderItemLast
        $State = _GUICtrlTreeViewGetState ($tvStrider, $i)
        If $State = $TVIS_SELECTED Then
            $Text = _GUICtrlTreeViewGetText ($tvStrider, $i)
            If StringLeft($Text, 1) = "*" Then
                ExitLoop
            Else
                Local $StriderIcon = $hmpPath & "\hitmanpro2.exe"
                Local $StriderIconID = 5
                _GUICtrlTreeViewSetIcon ($tvStrider, $i, $StriderIcon, $StriderIconID)
                _GUICtrlTreeViewSetText ($tvStrider, $i, "*" & $Text)
                ExitLoop
            EndIf
        EndIf
    Next
EndFunc  ;==>_btnStriderExclude

My function _btnStriderExclude() looks for the entry that has state $TVIS_SELECTED. I think this could be the problem.

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