eltorro Posted February 15, 2006 Share Posted February 15, 2006 In an Autoit3 GUI, how can one get the ControlId of an Item knowing only it's hWnd? Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Holger Posted February 15, 2006 Share Posted February 15, 2006 Maybe this: $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hWndCtrl) $ID = $ID[0] Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
eltorro Posted February 15, 2006 Author Share Posted February 15, 2006 Maybe this: $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd', $hWndCtrl) $ID = $ID[0] Hmmm... Am I applying this in the wrong fashion? Using the help file as a test bed. Select an item in the tree, click the Info button. --> Get the ctrl hwnd and then convert it back --> fails. expandcollapse popup#include <GUIConstants.au3> Global Const $TV_FIRST = 0x1100 Global Const $TVM_EXPAND = $TV_FIRST + 2 Global Const $TVE_TOGGLE = 0x0003 $GUI= GUICreate("My GUI with treeview", 350, 215) $treeview = GUICtrlCreateTreeView(6, 6, 100, 150, BitOr($TVS_HASBUTTONS, $TVS_HASLINES, $TVS_LINESATROOT, $TVS_DISABLEDRAGDROP, $TVS_SHOWSELALWAYS), $WS_EX_CLIENTEDGE) $generalitem = GUICtrlCreateTreeViewitem("General", $treeview) GUICtrlSetColor(-1, 0x0000C0) $displayitem = GUICtrlCreateTreeViewitem("Display", $treeview) GUICtrlSetColor(-1, 0x0000C0) $aboutitem = GUICtrlCreateTreeViewitem("About", $generalitem) $compitem = GUICtrlCreateTreeViewitem("Computer", $generalitem) $useritem = GUICtrlCreateTreeViewitem("User", $generalitem) $resitem = GUICtrlCreateTreeViewitem("Resolution", $displayitem) $otheritem = GUICtrlCreateTreeViewitem("Other", $displayitem) $startlabel = GUICtrlCreateLabel("TreeView Demo",190,90,100,20) $aboutlabel = GUICtrlCreateLabel("This little scripts demonstates the using of a treeview-control.", 190, 70, 100, 60) GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "aboutlabel"-text during initialization $compinfo = GUICtrlCreateLabel("Name:" & @TAB & @ComputerName & @LF & "OS:" & @TAB & @OSVersion & @LF & "SP:" & @TAB & @OSServicePack, 120, 30, 200, 80) GUICtrlSetState(-1, $GUI_HIDE) ; Hides the "compinfo"-text during initialization GUICtrlCreateLabel("", 0, 170, 350, 2, $SS_SUNKEN) $togglebutton = GUICtrlCreateButton("&Toggle", 35, 185, 70, 20) $infobutton = GUICtrlCreateButton("&Info", 105, 185, 70, 20) $statebutton = GUICtrlCreateButton("Col./Exp.", 175, 185, 70, 20) $cancelbutton = GUICtrlCreateButton("&Cancel", 245, 185, 70, 20) GUICtrlSetState($generalitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON)) ; Expand the "General"-item and paint in bold GUICtrlSetState($displayitem, BitOr($GUI_EXPAND,$GUI_DEFBUTTON)) ; Expand the "Display"-item and paint in bold GUISetState () While 1 $msg = GUIGetMsg() Select Case $msg = $cancelbutton Or $msg = $GUI_EVENT_CLOSE ExitLoop Case $msg = $togglebutton ; Toggle the bold painting If BitAnd(GUICtrlRead($generalitem), $GUI_DEFBUTTON) Then GUICtrlSetState($generalitem, 0) GUICtrlSetState($displayitem, 0) Else GUICtrlSetState($generalitem, $GUI_DEFBUTTON) GUICtrlSetState($displayitem, $GUI_DEFBUTTON) EndIf Case $msg = $infobutton $item = GUICtrlRead($treeview) ; Get the controlID of the current selected treeview item If $item = 0 Then MsgBox(64, "TreeView Demo", "No item currently selected") Else $hItem = GUICtrlGetHandle($item) $ID = DllCall('user32.dll', 'int', 'GetDlgCtrlID', 'hwnd',$hItem) $ID = $ID[0] ConsoleWrite("-->$ID : "&$ID&@LF) ConsoleWrite("-->$CtrlID : "&$item&@LF) $advmsg = GUICtrlRead($item, 1); Get advanced infos about the treeview item If ($advmsg[0] == 0) Then MsgBox(16, "Error", "Error while retrieving infos about item") Else MsgBox(64, "TreeView Demo", "Current item selected is: " & $advmsg[0]) ; $advmsg[0] contains the text and $advmsg[1] the state value of the treeview item EndIf EndIf Case $msg = $statebutton $item = GUICtrlRead($treeview) If $item > 0 Then $hItem = GUICtrlGetHandle($item) GuiCtrlSendMsg($treeview, $TVM_EXPAND, $TVE_TOGGLE, $hItem) EndIf ; The following items will hide the other labels (1st and 2nd parameter) and then show the 'own' labels (3rd and 4th parameter) Case $msg = $generalitem GUIChangeItems($aboutlabel, $compinfo, $startlabel, $startlabel) Case $msg = $aboutitem GUICtrlSetState ($compinfo, $GUI_HIDE) GUIChangeItems($startlabel, $startlabel, $aboutlabel, $aboutlabel) Case $msg = $compitem GUIChangeItems($startlabel, $aboutlabel, $compinfo, $compinfo) EndSelect WEnd GUIDelete() Exit Func GUIChangeItems($hidestart, $hideend, $showstart, $showend) Local $idx For $idx = $hidestart To $hideend GUICtrlSetState ($idx, $GUI_HIDE) Next For $idx = $showstart To $showend GUICtrlSetState ($idx, $GUI_SHOW) Next EndFunc Steve Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
Holger Posted February 15, 2006 Share Posted February 15, 2006 (edited) No, you can't get the 'controlID' cause an item is not a 'real' control! The treeview is the 'real' control. What you want to get is the itemID. If you want to get the ID of an item you have to take look in the GUITreeView-UDF in the helpfile and i.e. at google with "TVM_GETITEM". The question is: for what to you need this extra functionality, cause you already have the ID's of the items!? Edited February 15, 2006 by Holger Old project:GUI/Tray menu with icons and colors Other old stuff:IconFileScanner, TriState/ThreeState GUI TreeView, GUI ContextMenu created out of a TreeView Link to comment Share on other sites More sharing options...
eltorro Posted February 16, 2006 Author Share Posted February 16, 2006 No, you can't get the 'controlID' cause an item is not a 'real' control!The treeview is the 'real' control.What you want to get is the itemID.If you want to get the ID of an item you have to take look in the GUITreeView-UDF in the helpfile and i.e. at google with "TVM_GETITEM".The question is: for what to you need this extra functionality, cause you already have the ID's of the items!?I just wanted to know how to change back from hWnd. Some DllCall's return hWnd instead of control Id.I'm sure there is a use for it. Regards, [indent]ElTorro[/indent][font="Book"] Decide, Commit, Achieve[/font]_ConfigIO.au3Language Translation --uses Google(tm) MsgBox Move XML wrapper UDF XML2TreeView Zip functionality Split your GUI Save Print ScreenZipPluginEdit In Place listviewSome of my scripts on Google code Link to comment Share on other sites More sharing options...
MikelSevrel Posted March 6, 2006 Share Posted March 6, 2006 A followup question, I want to get the text from a dynamic treeviewitem when I click on it. Is there any way to do this? Coming soon.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now