Jump to content

How to keep control ID when we have only the handle


Recommended Posts

Hi, I haven't found any solution on french forums and hope you have one.

I have a GUICtrlTreeViewItem created by the _GUICtrlTreeView_InsertItem() function. It works, but this udf function returns the handle, and I found no way to keep the control ID that I need to check the item.

Is there a way to keep it, or a way to check the item using handle ?

Thanks

A+

Link to comment
Share on other sites

  • Moderators

JujuLand,

If you use the UDF function to create the TreeViewItem, then you need to use the other UDF functions to interact with it. Just use the handle you get as a return on creation to identify the item.

The ControlID returned by the native AutoIt function (GUICtrlCreateTreeViewItem) is actually the index of the control in the internal Autoit control array - if you use the UDF to create the Item, there will be no entry in the array and so a ControlID makes no sense.

Perhaps if you posted a small script to show the exact problem you are having we could offer some more help. :)

A bientot, ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

Thanks for the answer.

Well, I need the control ID to check the item with the function GUICrtlStatus(), so if there is no function to set it with the handle, I will must use another way.

For now, I only see one other way to insert an item (and keep the ID), but a bit complicated.

Add an item with GUICtrlCreateTreeViewItem (at the end of the TreeView)

And then in a for next boucle, beginning with the last item-1, copy the content to the next item , and set correctly the status, till the item where I want to insert the new item.

Have you a better way ?

Here is a short part of code how I'm doing for now (and missing) :

$rgItem=SearchExtRange($extNew,0)
   if $rgItem=-1 Then
        $sp1 = StringLeft($string,10-StringLen($extNew)) & "|"
        $sp2 = StringLeft($string,35-StringLen("Win2Tux.file")) & "|"
        $sp3 = StringLeft($string,23)
        $item= StringLower($extNew) & $sp1 & "Win2Tux.file"  & $sp2 & $sp3
        $rgItem=SearchPosInExt($extNew) ; return the range where the new item must be inserted (after this range)
        msgbox(0,"pos",$rgItem)
        $handle=_GUICtrlTreeView_InsertItem($extensionView,$item,0,$extArray[$rgItem][4]) ;
        $nbExt+=1
        ReDim $extArray[$nbExt+1][5]
     for $rg=$nbExt  To $rgItem+1
             for $col=0 to 5
               $extArray[$rg][$col] = $extArray[$rg-1][$col]
            Next
     Next
        $extArray[$rgItem][0] =$extNew
        $extArray[$rgItem][1] ="Win2Tux.file"
        $extArray[$rgItem][2] =""
        $extArray[$rgItem][3] =$handle                                      ;  <<< I need here to keep the controlID
        $extArray[$rgItem][4] =$handle
        GUICtrlSetState($extArray[$rgItem][3], $GUI_CHECKED)   ; <<< for now, it can't work
        $nbW2T+=1
        GUICtrlSetData($W2Tnumber,$nbW2T)
        Cancel0()
        _WinAPI_RedrawWindow($MyGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))
   Else
        msgbox(0,$txt120,$txt121 & $extNew & $txt122)
   EndIf

Thanks

A+

Edited by JujuLand
Link to comment
Share on other sites

  • Moderators

JujuLand,

I need the control ID to check the item with the function GUICrtlStatus

What function is that? Is it a UDF? If so where is the code because it is not one of the standard ones. ;)

Looking at that code (which makes little sense out of context) I see you are trying to use GUICtrlSetState($extArray[$rgItem][3], $GUI_CHECKED) to check an item. As I explained above, if the item is created with the UDF function, you cannot use the native Autoit functions to interact with it as you do not have a ControlID, only a handle. But the UDF _GUICtrlTreeView_SetChecked function is designed to check/uncheck items created by the UDF, so try using that instead. :)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

You're right, it was a typo. It ought to be GUICrtlSetStatus() instead of GUICrtlStatus().

In conclusion, it's better to use generic functions for control creation, as we keep controlID and we can found handle. For deletion, UDF works without problem.

I have modified the code to use generic functions:

if $rgItem=-1 Then
        $sp1 = StringLeft($string,10-StringLen($extNew)) & "|"
        $sp2 = StringLeft($string,35-StringLen("Win2Tux.file")) & "|"
        $sp3 = StringLeft($string,23)
        $item= StringLower($extNew) & $sp1 & "Win2Tux.file"  & $sp2 & $sp3
        $rgItem=SearchPosInExt($extNew)
        $value=GUICtrlRead($ExtArray[$nbExt-1][3],1)
        $controlID=GUICtrlCreateTreeViewItem(GUICtrlRead($ExtArray[$nbExt-1][3],1),$extensionView)
        $handle=GUICtrlGetHandle($controlID)
        GUICtrlSetState($controlID,GUICtrlRead($ExtArray[$nbExt-1][3]))
        $nbExt+=1
        ReDim $extArray[$nbExt+1][5]
        $extArray[$nbExt][3]=$controlID
        $extArray[$nbExt][4]=$handle
        GUICtrlSetOnEvent($ExtArray[$nbExt][3], "extension")
        for $rg=$nbExt -1 To $rgItem+2 step -1
              for $col=0 to 3
                   $extArray[$rg][$col] = $extArray[$rg-1][$col]
             Next
             GUICtrlSetData($extArray[$rg+1][ 3],GUICtrlRead($extArray[$rg][3],1))
             GUICtrlSetState($extArray[$rg+1][ 3],GUICtrlRead($extArray[$rg][3]))
        Next
        GUICtrlSetData($extArray[$rgItem+1][ 3],GUICtrlRead($extArray[$rgItem][3],1))
        $extArray[$rgItem+1][0] =$extNew
        $extArray[$rgItem+1][1] ="Win2Tux.file"
        $extArray[$rgItem+1][2] =$controlID
        GUICtrlSetData($extArray[$rgItem+1][ 3],$item)
        GUICtrlSetState($extArray[$rgItem+1][3], $GUI_CHECKED)
        $nbW2T+=1
        GUICtrlSetData($W2Tnumber,$nbW2T)
        Cancel0()
        _WinAPI_RedrawWindow($MyGUI, "", "", BitOR($RDW_INVALIDATE, $RDW_UPDATENOW))
   Else
      msgbox(0,$txt120,$txt121 & $extNew & $txt122)
   EndIf

Thanks for the help

A+

Edited by JujuLand
Link to comment
Share on other sites

  • Moderators

JujuLand,

Il n'y a pas de quoi. ;)

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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