Jump to content

ControlTreeView


Recommended Posts

hi i wanne get in to the hardware manager and expend the networkdevices but something dont fully work i shall explane what i want

i want a script that automaticly opens the hardware manager then expend the networkdevices and hit a right click on the first device and klik proppeties then go to the tab powercontrol and there is a checkbox with the computer may disable this network device to save power.. and then he needs to close the window and then click the secend network adapter and do the same this needs to repeat himself until he is at the end of the tree of the network devices and when he is done he needs to clise the hardware manager al am already trying to get it working but i dont have suc6

i'm nl so the script is written for nl

i just dont understand why this peace of code dont expend the "Netwerkadapters" (so that are the network devices)

can somebody help me a little bit with this?

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", "Netwerkadapters")

Link to comment
Share on other sites

First of all, I use Vista. But what I am about to say is, I think, true for XP as well.

I did the same with your script and got the same 'no-result'.

Try this: And replace <computername> with YOUR computername!!

#RequireAdmin
Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)
winwait("Apparaatbeheer")
Sleep(1500)
ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", "<computername>|Netwerkadapters")

If this works it proves 2 things:

1) Wait a little longer then the winwait because even when the window is there, the content still isn't (on my laptop)

2) The ListView32 has a header, so you have to specify that first. Hench the "<computername>|Netwerkadapters"

----------------------------

Dutch below

----------------------------

Seeing the window title and you writing I think you Dutch so I will translate for you:

Allereerst, I gebruik Vista. Maar wat ik ga vertellen is, denk ik, ook waar voor XP.

Ik heb hetzelfde resultaat gekregen met je script als dat jij krijgt.

Probeer bovenstaande code and vervang <computername> met JOU computernaam!!

Als dit werkt verteld het je 2 dingen:

1) Wacht iets langer dan de winwait omdat ookal is het scherm er al, de inhoud nog niet (op mijn laptop)

2) De ListView32 heeft een kop, dus je moet die eerst specificeren. Hierdoor dus "<computername>|Netwerk adapters"

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

First of all, I use Vista. But what I am about to say is, I think, true for XP as well.

I did the same with your script and got the same 'no-result'.

Try this: And replace <computername> with YOUR computername!!

#RequireAdmin
Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)
winwait("Apparaatbeheer")
Sleep(1500)
ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", "<computername>|Netwerkadapters")

If this works it proves 2 things:

1) Wait a little longer then the winwait because even when the window is there, the content still isn't (on my laptop)

2) The ListView32 has a header, so you have to specify that first. Hench the "<computername>|Netwerkadapters"

----------------------------

Dutch below

----------------------------

Seeing the window title and you writing I think you Dutch so I will translate for you:

Allereerst, I gebruik Vista. Maar wat ik ga vertellen is, denk ik, ook waar voor XP.

Ik heb hetzelfde resultaat gekregen met je script als dat jij krijgt.

Probeer bovenstaande code and vervang <computername> met JOU computernaam!!

Als dit werkt verteld het je 2 dingen:

1) Wacht iets langer dan de winwait omdat ookal is het scherm er al, de inhoud nog niet (op mijn laptop)

2) De ListView32 heeft een kop, dus je moet die eerst specificeren. Hierdoor dus "<computername>|Netwerk adapters"

hi i tryed with @ComputerName and that worked because the script needs to work on more then one computer can u help me on? now i need to make a loop that click the first network device and hit rightmouse click hit the tab powercontrol/energiebeheer there is a checkbox this checkbox beed to Unchecked with the computer may disable this device to save power/de computer mag dit apparaat uitschakelen om energie te besparen then click ok and go to the secenc networkdevice he needs to repeat this loop antil he is done with the last networkdevice.. is something like this possebel?

Link to comment
Share on other sites

something like this

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Networkadapters|#1")

but it dont work.

Edited by yucatan
Link to comment
Share on other sites

Without trying: You have a typo in the second ControlTreeView.

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Networkadapters|#1")

My active project(s): A-maze-ing generator (generates a maze)

My archived project(s): Pong3 (Multi-pinger)

Link to comment
Share on other sites

thx triblade but it still dont work i have experimented with the syntax and tryed alot of thing but he dont seleck the first network device and dubbleclick on it..

i just dont know what to do but i'm still trying different things but it just wont work..:D

Edited by yucatan
Link to comment
Share on other sites

Try adding another sleep between the 2 ControlTreeView's. Sleep(500) or so

Then try simulating an 'Enter' press after the second CTV with this:

Send("{ENTER}")

hi tribalde i did try what u sad but it just dont select it...

i'm trying with what u sad th ENTER and sleep but it still dont select it..

Link to comment
Share on other sites

If I need to work with devices, I prefer the command line with DEVCON.exe. But this is a good chance to play with the new _GuiCtrlTreeView_* UDFs:

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 4)

ShellExecute("devmgmt.msc")

WinWait("[CLASS:MMCMainFrame; TITLE:Device Manager]")
$hWin = WinGetHandle("[CLASS:MMCMainFrame; TITLE:Device Manager]")
WinActivate($hWin)
WinWaitActive($hWin)

$hSTV = ControlGetHandle($hWin, "", "SysTreeView321")
$iCount = _GUICtrlTreeView_GetCount($hSTV)
ConsoleWrite("Debug:  STV Total Items $iCount = " & $iCount & @LF)

$hSTV_Item = _GUICtrlTreeView_GetFirstItem($hSTV)
$sItemText = _GUICtrlTreeView_GetText($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Top item $sItemText = " & $sItemText & @LF)

$iChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Item Child $iChildCount = " & $iChildCount & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, "Network adapters", True, $hSTV_Item)
If $hChildNetwork = 0 Then
    MsgBox(16, "Error", "Failed to find Network adapters child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found child item = " & $hChildNetwork & @LF)
_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

If you are not using English, the "Network adapters" text may have to be changed for the search, but you can figure it out from here.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hi PsaltyDS srry but i dont understand what u mean should this code need to work i cant read the code i dont understand what its doing and secend i dont want a GUI i just want a script that do some steps at the device manager.. did u read what i posted here in top ?

this is the code that i already had..

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

Sleep(500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|#1")

Send("{ENTER}")

but clicking on the network adapter dont work..

Edited by yucatan
Link to comment
Share on other sites

hi PsaltyDS srry but i dont understand what u mean should this code need to work i cant read the code i dont understand what its doing and secend i dont want a GUI i just want a script that do some steps at the device manager.. did u read what i posted here in top ?

this is the code that i already had..

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

Sleep(500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|#1")

Send("{ENTER}")

but clicking on the network adapter dont work..

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

Sleep(500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|Realtek RTL8139 Family PCI Fast Ethernet NIC")

this is the code now .. there is still one problem the Select rule just dont work and i'm sure that he exsist because when i do

$result = ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Exists", @ComputerName & "|Netwerkadapters|Realtek RTL8139 Family PCI Fast Ethernet NIC")

MsgBox(0, "AutoIt Example", "Count is: " & $result)

i get a 1 so thats good that means he exsist can somebody help me why it just not select the Realtek RTL8139 Family PCI Fast Ethernet NIC

thx alot bye

Link to comment
Share on other sites

Sorry for being too vague about it. All I meant to show was that there are UDFs in GuiTreeView.au3 for dealing with SysTreeView32 controls, and that they work on the Device Manager's SysTreeView321.

The code I posted requires a 3.2.11.x Beta version minimum (tested with 3.2.11.5). The native ControlTreeView() function does not have nearly as much functionality as the UDF. If run from SciTE with Alt-F5 (Beta Run) and one of the latest Beta versions loaded, it will open the device manager, list the subitems under the local computer, and expand the "Network adapters" item. I thought it was clear how the rest of what you wanted would be done from there.

If you get it working with the native function, more power to ya!

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hmm i already sad the expending works but when i run this

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

Sleep(500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|Realtek RTL8139 Family PCI Fast Ethernet NIC")

it works but this fucktie dont work

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|Realtek RTL8139 Family PCI Fast Ethernet NIC")

the SELECT just dont work

PsaltyDS maby u can try to look why my SELECT rule dont work and if u dont get it working maby u want to help me slowy to build it with the _GuiCtrlTreeView_* but ishall be honest i dont work with variable so much so when i look to you peace of code u send me i see nothing i cant see some structure in it... i need to learn that more thx alot from here

Link to comment
Share on other sites

hmm i already sad the expending works but when i run this

#RequireAdmin

Run(@ComSpec & " /c " & 'devmgmt.msc', "", @SW_HIDE)

winwait("Apparaatbeheer")

Sleep(1500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Expand", @ComputerName & "|Netwerkadapters")

Sleep(500)

ControlTreeView("Apparaatbeheer", "", "[Class:SysTreeView32; Instance:1]", "Select", @ComputerName & "|Netwerkadapters|Realtek RTL8139 Family PCI Fast Ethernet NIC")

the SELECT just dont work

PsaltyDS maby u can try to look why my SELECT rule dont work and if u dont get it working maby u want to help me slowy to build it with the _GuiCtrlTreeView_* but ishall be honest i dont work with variable so much so when i look to you peace of code u send me i see nothing i cant see some structure in it... i need to learn that more thx alot from here

There is some trickiness here. Just because an item is selected, doesn't mean its onclick event has been triggered, and also doesn't mean its GUI display changes.

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 4)

ShellExecute("devmgmt.msc")

WinWait("[CLASS:MMCMainFrame; TITLE:Device Manager]")
$hWin = WinGetHandle("[CLASS:MMCMainFrame; TITLE:Device Manager]")
WinActivate($hWin)
WinWaitActive($hWin)

$hSTV = ControlGetHandle($hWin, "", "SysTreeView321")
$iCount = _GUICtrlTreeView_GetCount($hSTV)
ConsoleWrite("Debug:  STV Total Items $iCount = " & $iCount & @LF)

$hSTV_Item = _GUICtrlTreeView_GetFirstItem($hSTV)
$sItemText = _GUICtrlTreeView_GetText($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Top item $sItemText = " & $sItemText & @LF)

$iChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Item Child $iChildCount = " & $iChildCount & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, "Network adapters", True, $hSTV_Item)
If $hChildNetwork = 0 Then
    MsgBox(16, "Error", "Failed to find Network adapters child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found Network child item = " & $hChildNetwork & @LF)
_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

$hRealtek = _GUICtrlTreeView_FindItem($hSTV, "Realtek", True, $hChildNetwork)
If $hRealtek = 0 Then
    MsgBox(16, "Error", "Failed to find Realtek adapter child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found Realtek child item = " & $hRealtek & @LF)


_GUICtrlTreeView_SelectItem($hSTV, $hRealtek, True)
ConsoleWrite("Debug: Current selection: " & _GUICtrlTreeView_GetSelection($hSTV) & @LF)
ConsoleWrite("Debug: Note item is current selection, but does not appear to be selected on the GUI." & @LF)
Sleep(5000)

_GUICtrlTreeView_ClickItem($hSTV, $hRealtek)
ConsoleWrite("Debug: NOW it should be selected, and the onclick event should have enabled the properties icons." & @LF)

There are functions for SelectItem, SetSelected, and SetState with $TVIS_SELECTED, but they all appear to do nothing based on viewing the GUI. ClickItem triggers the MMC to update the GUI presentation.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

There is some trickiness here. Just because an item is selected, doesn't mean its onclick event has been triggered, and also doesn't mean its GUI display changes.

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 4)

ShellExecute("devmgmt.msc")

WinWait("[CLASS:MMCMainFrame; TITLE:Device Manager]")
$hWin = WinGetHandle("[CLASS:MMCMainFrame; TITLE:Device Manager]")
WinActivate($hWin)
WinWaitActive($hWin)

$hSTV = ControlGetHandle($hWin, "", "SysTreeView321")
$iCount = _GUICtrlTreeView_GetCount($hSTV)
ConsoleWrite("Debug:  STV Total Items $iCount = " & $iCount & @LF)

$hSTV_Item = _GUICtrlTreeView_GetFirstItem($hSTV)
$sItemText = _GUICtrlTreeView_GetText($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Top item $sItemText = " & $sItemText & @LF)

$iChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hSTV_Item)
ConsoleWrite("Debug:  Item Child $iChildCount = " & $iChildCount & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, "Network adapters", True, $hSTV_Item)
If $hChildNetwork = 0 Then
    MsgBox(16, "Error", "Failed to find Network adapters child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found Network child item = " & $hChildNetwork & @LF)
_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

$hRealtek = _GUICtrlTreeView_FindItem($hSTV, "Realtek", True, $hChildNetwork)
If $hRealtek = 0 Then
    MsgBox(16, "Error", "Failed to find Realtek adapter child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found Realtek child item = " & $hRealtek & @LF)


_GUICtrlTreeView_SelectItem($hSTV, $hRealtek, True)
ConsoleWrite("Debug: Current selection: " & _GUICtrlTreeView_GetSelection($hSTV) & @LF)
ConsoleWrite("Debug: Note item is current selection, but does not appear to be selected on the GUI." & @LF)
Sleep(5000)

_GUICtrlTreeView_ClickItem($hSTV, $hRealtek)
ConsoleWrite("Debug: NOW it should be selected, and the onclick event should have enabled the properties icons." & @LF)

There are functions for SelectItem, SetSelected, and SetState with $TVIS_SELECTED, but they all appear to do nothing based on viewing the GUI. ClickItem triggers the MMC to update the GUI presentation.

:D

hmm srry i dont understand what do you mean with this rule

There are functions for SelectItem, SetSelected, and SetState with $TVIS_SELECTED, but they all appear to do nothing based on viewing the GUI. ClickItem triggers the MMC to update the GUI presentation.

i dont understand whatr you wanne say with it

Link to comment
Share on other sites

hmm srry i dont understand what do you mean with this rule

There are functions for SelectItem, SetSelected, and SetState with $TVIS_SELECTED, but they all appear to do nothing based on viewing the GUI. ClickItem triggers the MMC to update the GUI presentation.

i dont understand whatr you wanne say with it

An item in a SysTreeView32 control can BE selected, but not LOOK selected. The application that owns the GUI (devmgmt.mmc in this case), may not notice that you have changed the state of an item to "Selected". I used _GUICtrlTreeView_ClickItem() to trigger the events in the application that would cause it to notice the change and update the GUI.

The code I posted works under English XP Pro SP2 with AutoIt 3.2.11.5 Beta. You might have to edit the item names (i.e. "Network adapters") for your language.

If is not clear enough for you, this might require a native speaker of your language to interpret.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

hmm i got it runt th script(BETA) i need to use but i have a nother problem and i'm thinking and trying but i dont know how to do it

now the script needs to do this\

look whats the first network child put it in a $

whats the secend network child and put it in a $ and so in a loop until there is no left so he has found them all

so when the computer has 3 network childs then he sads i have found 3 network childs

$childone=

$childtwo=

$childtree=

so that i can detect hoemany network child there are

after that there needs to becom another loop just a couple of spets of clicks he needs to do first on the first network child then on the secend and then on last is this possebel thx you vary much for the code..

Edited by yucatan
Link to comment
Share on other sites

hmm i got it runt th script(BETA) i need to use but i have a nother problem and i'm thinking and trying but i dont know how to do it

now the script needs to do this\

look whats the first network child put it in a $

whats the secend network child and put it in a $ and so in a loop until there is no left so he has found them all

so when the computer has 3 network childs then he sads i have found 3 network childs

$childone=

$childtwo=

$childtree=

so that i can detect hoemany network child there are

after that there needs to becom another loop just a couple of spets of clicks he needs to do first on the first network child then on the secend and then on last is this possebel thx you vary much for the code..

You need to experiment more with the GuiTreeView.au3 UDF functions:

_GUICtrlTreeView_GetChildCount()

_GUICtrlTreeView_GetFirstChild()

_GUICtrlTreeView_GetNextChild()

etc.

There will be a learning curve, but it's worth it.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

PsaltyDS i Love you i have found it pleas look at this peace of code you wrote the top side so you know what i mean :D

$iChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hSTV_Item)

ConsoleWrite("Debug: Item Child $iChildCount = " & $iChildCount & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, "Netwerkadapters", True, $hSTV_Item)

If $hChildNetwork = 0 Then

MsgBox(16, "Error", "Failed to find Network adapters child handle.")

Exit

EndIf

ConsoleWrite("Debug: Found Network child item = " & $hChildNetwork & @LF)

_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

$iNetworkChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hChildNetwork)

MsgBox(0, "AutoIt Example", "Count is: " & $iNetworkChildCount)

hi

i still have one problem maby u guys can help me out lissen this is it

when i expend Network Devices

and i run this code then he Selects the first Network Device Below his Parant NetworkDevices

$iFirstNetworkChild = _GUICtrlTreeView_GetFirstChild ($hSTV, $hChildNetwork)

ConsoleWrite("Debug: Found First Network child item = " & $hChildNetwork & @LF)

so thats fine that works

when i run this code he gets the next in the headtree so thats Unknow Devices on my Computer and NOT the next below his parant NetwerkDevices so NOT the Secend network device

$iNextNetworkChild = _GUICtrlTreeView_GetNextChild ($hSTV, $hChildNetwork)

ConsoleWrite("Debug: Found First Network child item = " & $hChildNetwork & @LF)

the piont is i want that he select the Secend Network device Below his parant

NOT that he Select the next item in the head tree so thats Unknow Devices with me can somebody help me with this

this is my total script

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 4)

ShellExecute("devmgmt.msc")

WinWait("[CLASS:MMCMainFrame; TITLE:Apparaatbeheer]")

$hWin = WinGetHandle("[CLASS:MMCMainFrame; TITLE:Apparaatbeheer]")

WinActivate($hWin)

WinWaitActive($hWin)

$hSTV = ControlGetHandle($hWin, "", "SysTreeView321")

$iCount = _GUICtrlTreeView_GetCount($hSTV)

ConsoleWrite("Debug: STV Total Items $iCount = " & $iCount & @LF)

$hSTV_Item = _GUICtrlTreeView_GetFirstItem($hSTV)

$sItemText = _GUICtrlTreeView_GetText($hSTV, $hSTV_Item)

ConsoleWrite("Debug: Top item $sItemText = " & $sItemText & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, "Netwerkadapters", True, $hSTV_Item)

If $hChildNetwork = 0 Then

MsgBox(16, "Error", "Failed to find Network adapters child handle.")

Exit

EndIf

ConsoleWrite("Debug: Found Netwerkadapters Handle Item = " & $hChildNetwork & @LF)

_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

$iNetworkChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hChildNetwork)

ConsoleWrite("Debug: Item Child $iChildCount = " & $iNetworkChildCount & @LF)

$iFirstNetworkChild = _GUICtrlTreeView_GetFirstChild ($hSTV, $hChildNetwork)

ConsoleWrite("Debug: Found First Network child item = " & $hChildNetwork & @LF)

$iNextNetworkChild = _GUICtrlTreeView_GetNextChild ($hSTV, $hChildNetwork)

ConsoleWrite("Debug: Found First Network child item = " & $hChildNetwork & @LF)

_GUICtrlTreeView_SelectItem($hSTV, $iFirstNetworkChild, True)

ConsoleWrite("Debug: Current selection: " & _GUICtrlTreeView_GetSelection($hSTV) & @LF)

ConsoleWrite("Debug: Note item is current selection, but does not appear to be selected on the GUI." & @LF)

Sleep(500)

_GUICtrlTreeView_ClickItem($hSTV, $iFirstNetworkChild)

ConsoleWrite("Debug: NOW it should be selected, and the onclick event should have enabled the properties icons." & @LF)

Send("{ENTER}")

Sleep(5000)

_GUICtrlTreeView_SelectItem($hSTV, $iNextNetworkChild, True)

ConsoleWrite("Debug: Current selection: " & _GUICtrlTreeView_GetSelection($hSTV) & @LF)

ConsoleWrite("Debug: Note item is current selection, but does not appear to be selected on the GUI." & @LF)

Sleep(500)

Edited by yucatan
Link to comment
Share on other sites

It is confusing, and took some experimenting for me to see how it works (the help file entries on the new UDFs will improve over time, but they are a little weak right now). The main thing is that when you use "GetFirstChild" you have to provide the handle of the parent item, but when you do "GetNextChild" you have to provide the handle of the child before it, not the parent item. Updated the demo to show that, and put the language specific strings at the top so they can be changed easily:

#include <GuiTreeView.au3>

Opt("WinTitleMatchMode", 4)

Global $sItemName = "Network adapters", $sDevMgmt = "Device Manager" ; English
; Globlal $sItemName = "Netwerkadapters", $sDevMgmt = "Apparaatbeheer" ; Uhmm... not English

ShellExecute("devmgmt.msc")

WinWait("[CLASS:MMCMainFrame; TITLE:" & $sDevMgmt & "]")
$hWin = WinGetHandle("[CLASS:MMCMainFrame; TITLE:" & $sDevMgmt & "]")
WinActivate($hWin)
WinWaitActive($hWin)

$hSTV = ControlGetHandle($hWin, "", "SysTreeView321")
$iCount = _GUICtrlTreeView_GetCount($hSTV)
ConsoleWrite("Debug: STV Total Items $iCount = " & $iCount & @LF)

$hSTV_Item = _GUICtrlTreeView_GetFirstItem($hSTV)
$sItemText = _GUICtrlTreeView_GetText($hSTV, $hSTV_Item)
ConsoleWrite("Debug: Top item $sItemText = " & $sItemText & @LF)

$iChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hSTV_Item)
ConsoleWrite("Debug: Item Child $iChildCount = " & $iChildCount & @LF)

$hChildNetwork = _GUICtrlTreeView_FindItem($hSTV, $sItemName, True, $hSTV_Item)
If $hChildNetwork = 0 Then
    MsgBox(16, "Error", "Failed to find " & $sItemName & " child handle.")
    Exit
EndIf
ConsoleWrite("Debug: Found " & $sItemName & " child item = " & $hChildNetwork & @LF)

_GUICtrlTreeView_Expand($hSTV, $hChildNetwork, True)

$iNetworkChildCount = _GUICtrlTreeView_GetChildCount($hSTV, $hChildNetwork)
ConsoleWrite("$iNetworkChildCount = " & $iNetworkChildCount & @LF)

Global $avAdapters[$iNetworkChildCount]
$avAdapters[0] = _GUICtrlTreeView_GetFirstChild($hSTV, $hChildNetwork)
For $n = 1 To $iNetworkChildCount - 1
    $avAdapters[$n] = _GUICtrlTreeView_GetNextChild($hSTV, $avAdapters[$n - 1])
Next

For $n = 0 To UBound($avAdapters) - 1
    ConsoleWrite("Debug: Adapter " & $n & ": Text: " & _GUICtrlTreeView_GetText($hSTV, $avAdapters[$n]) & @LF)
Next

This uses GetFirstChild/GetNextChild to retrieve the handles to all the child items, and saves them to an array. That makes it easy to walk the array and do something with all of them, like display their text.

:D

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
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...