VeeDub Posted September 20, 2023 Share Posted September 20, 2023 Hello, I am using AutoIt to interact / automate an application. So far I have been able to complete all the interaction using commands like: WinActivate, WinActive and in terms of passing commands: ControlSend However, I now have a control, that I need to interact with and I need to decide how to proceed. I need to click on the highlighted row (which in the first screenshot, I've done using the mouse (because I haven't yet figured out how to click on the row using AutoIt) and then either right-click and select an option or click on Virtual Machine (which I've just noticed is missing from the 1st screenshot). I've attached three screenshots 1. The application - Macrium viBoot. I want to interact with the Virtual Machine in the list, which is highlighted in blue. 2. AutoIt Window Info - which unfortunately displays very little information about the Control. 3. UIASpy - which provides a lot more info on the control, which is encouraging. However, I did some work with UIASpy a few years ago, and back then had trouble getting my head around how to work with it. I'm hoping that it might be possible to use the info reported by UIASpy with the some of the non-UIA UDF's; and if that might be possible - then just after some tips on how to go about it. Otherwise, I'm going to have to start from scratch on using UIASpy and hope that I find it more straightforward than when I last tried using it. Thank you. VW Link to comment Share on other sites More sharing options...
Solution Andreik Posted September 20, 2023 Solution Share Posted September 20, 2023 For your specific case you can do something like this: Local $hWindow = WinGetHandle('Macrium viBoot - Hyper-V') Local $hListView = ControlGetHandle($hWindow, '', 'SysListView322') _GUICtrlListView_ClickItem($hListView, 0) But if you want to click a specific list view item with a certain text, you might want to use _GUICtrlListView_FindText() to get the index of the item with a specific text and then you can use _GUICtrlListView_ClickItem() with that index. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
VeeDub Posted September 20, 2023 Author Share Posted September 20, 2023 Hello Andreik, This was exactly what I was hoping for. However, _GUICtrlListView_ClickItem isn't working for me. #include <GuiListView.au3> Local $FILES[1][2] $FILES[0][0] = "2CBB750B554D2444-109-109.mrimg" ; Make viBoot active window with focus Local $bWndIsActive = False Do Local $hWnd = WinActivate("Macrium viBoot - Hyper-V") Sleep(1000) $bWndIsActive = WinActive($hWnd) Until ($bWndIsActive) Sleep(1000) ; Shutdown Virtual Machine ; Find Virtual Machine - Obtain Index Local $ListViewFindText = "viBoot - " & $FILES[0][0] Local $Index $Index = _GUICtrlListView_FindText($hWnd,$ListViewFindText) ConsoleWrite("Index: " & $Index & @CRLF) Sleep(1000) ; Click Virtual Machine _GUICtrlListView_ClickItem($hWnd,$Index,"right",True,1) In the console, Index = 0 So, that means that _GUICtrlListView_FindText was successful. But then after that, nothing happens, the right-click menu for the Virtual Machine does not appear. Also, when I right-click manually, the Virtual Machine entry in the list is highlighted in blue to indicate which entry has been right-clicked. When the script runs, the Virtual Machine is not highlighted in blue either. Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2023 Share Posted September 21, 2023 9 hours ago, VeeDub said: _GUICtrlListView_ClickItem($hWnd,$Index,"right",True,1) Why do you use a window handle when it's obviously required a list view handle? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
VeeDub Posted September 21, 2023 Author Share Posted September 21, 2023 1 hour ago, Andreik said: Why do you use a window handle when it's obviously required a list view handle? I'm afraid that wasn't obvious to me. But thanks for pointing that out. I will review and update. Link to comment Share on other sites More sharing options...
Andreik Posted September 21, 2023 Share Posted September 21, 2023 You have in my first post an example of how to get the handle of list view. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
VeeDub Posted September 21, 2023 Author Share Posted September 21, 2023 7 hours ago, Andreik said: You have in my first post an example of how to get the handle of list view. I should have been paying closer attention. Thanks! Link to comment Share on other sites More sharing options...
VeeDub Posted December 13, 2023 Author Share Posted December 13, 2023 On 9/21/2023 at 4:25 AM, Andreik said: For your specific case you can do something like this: Local $hWindow = WinGetHandle('Macrium viBoot - Hyper-V') Local $hListView = ControlGetHandle($hWindow, '', 'SysListView322') _GUICtrlListView_ClickItem($hListView, 0) But if you want to click a specific list view item with a certain text, you might want to use _GUICtrlListView_FindText() to get the index of the item with a specific text and then you can use _GUICtrlListView_ClickItem() with that index. Hello, I've been using code, based on the above post which up until now has been working fine. However, up until now the ListView control has only had a single item in the list, and as a result I think the index has been defaulting to 0, which by good fortune has had the desired result. I now have a scenario where the ListView has two items in the list and the code is not selecting the correct item. Here is a code snippet $FILES[0][0] = "viBoot - FS1-110-110.mrimg" Local $ListViewFindText = "viBoot - " & $FILES[0][0] Local $hWindow = WinGetHandle("Macrium viBoot - Hyper-V") UpdateEventLog("$hWindow: " & $hWindow) Local $hListView = ControlGetHandle($hWindow, "", "List:SysListView32") UpdateEventLog("$hListView: " & $hListView) Local $Index $Index = _GUICtrlListView_FindText($hListView,$ListViewFindText) UpdateEventLog("ListViewFindText: " & $ListViewFindText) UpdateEventLog("Index: " & $Index) Sleep(1000) ; Click Virtual Machine _GUICtrlListView_ClickItem($hListView,$Index,"right",True,1) Sleep(2000) And here is the logging 2023-12-13 Wed 16:32 $hWindow: 0x0013052E 2023-12-13 Wed 16:32 $hListView: 0x00000000 2023-12-13 Wed 16:32 ListViewFindText: viBoot - viBoot - FS1-110-110.mrimg 2023-12-13 Wed 16:32 Index: 0 This statement is not working. Local $hListView = ControlGetHandle($hWindow, "", "List:SysListView32") The right-click, is clicking on the desktop, rather than the List control. I've also tried the following arguments for: $hListView Local $hListView = ControlGetHandle($hWindow, "", "List:SysListView32") Local $hListView = ControlGetHandle($hWindow, '', 'List:SysListView32') Local $hListView = ControlGetHandle($hWindow, '', 'SysListView32') Would appreciate some suggestions on how to troubleshoot. Thanks Link to comment Share on other sites More sharing options...
VeeDub Posted December 13, 2023 Author Share Posted December 13, 2023 Hello, I've just noticed one error with my example snippet. The ListViewFindText had an error. However, correcting that is not the answer. Updated snippet $FILES[0][0] = "viBoot - FS1-110-110.mrimg" Local $ListViewFindText = $FILES[0][0] Local $hWindow = WinGetHandle("Macrium viBoot - Hyper-V") UpdateEventLog("$hWindow: " & $hWindow) Local $hListView = ControlGetHandle($hWindow, "", "List:SysListView32") UpdateEventLog("$hListView: " & $hListView) Local $Index $Index = _GUICtrlListView_FindText($hListView,$ListViewFindText) UpdateEventLog("ListViewFindText: " & $ListViewFindText) UpdateEventLog("Index: " & $Index) Sleep(1000) ; Click Virtual Machine _GUICtrlListView_ClickItem($hListView,$Index,"right",True,1) Sleep(2000) Log 2023-12-13 Wed 16:47 $hWindow: 0x0013052E 2023-12-13 Wed 16:47 $hListView: 0x00000000 2023-12-13 Wed 16:47 ListViewFindText: viBoot - FS1-110-110.mrimg 2023-12-13 Wed 16:47 Index: 0 The desktop is still being right-clicked. In this instance, the $FILES[0][0] item is the 2nd entry in the list, so I imagine that if the ListView handle works, then the Index will be: 1 Link to comment Share on other sites More sharing options...
VeeDub Posted December 13, 2023 Author Share Posted December 13, 2023 Hello, I have made some progress $FILES[0][0] = "viBoot - FS1-110-110.mrimg" Local $ListViewFindText = $FILES[0][0] Local $hWindow = WinGetHandle("Macrium viBoot - Hyper-V") UpdateEventLog("$hWindow: " & $hWindow) Local $hListView = ControlGetHandle($hWindow, "", "[CLASS:SysListView32; INSTANCE:2]") UpdateEventLog("$hListView: " & $hListView) Local $Index ; $Index = _GUICtrlListView_FindText($hListView,$ListViewFindText) ; UpdateEventLog("ListViewFindText: " & $ListViewFindText) ; UpdateEventLog("Index: " & $Index) Sleep(1000) Local $ListView_GetItem_0[8] $ListView_GetItem_0 = _GUICtrlListView_GetItem($hListView,0) UpdateEventLog("$ListView_GetItem_0[0]: " & $ListView_GetItem_0[0]) UpdateEventLog("$ListView_GetItem_0[1]: " & $ListView_GetItem_0[1]) UpdateEventLog("$ListView_GetItem_0[2]: " & $ListView_GetItem_0[2]) UpdateEventLog("$ListView_GetItem_0[3]: " & $ListView_GetItem_0[3]) UpdateEventLog("$ListView_GetItem_0[4]: " & $ListView_GetItem_0[4]) UpdateEventLog("$ListView_GetItem_0[5]: " & $ListView_GetItem_0[5]) UpdateEventLog("$ListView_GetItem_0[6]: " & $ListView_GetItem_0[6]) UpdateEventLog("$ListView_GetItem_0[7]: " & $ListView_GetItem_0[7]) With this code, I am able to get a handle to the ListView. 2023-12-14 Thu 09:07 $hWindow: 0x016E047E 2023-12-14 Thu 09:07 $hListView: 0x0023056E 2023-12-14 Thu 09:07 $ListView_GetItem_0[0]: 2023-12-14 Thu 09:07 $ListView_GetItem_0[1]: 0 2023-12-14 Thu 09:07 $ListView_GetItem_0[2]: 0 2023-12-14 Thu 09:07 $ListView_GetItem_0[3]: 2023-12-14 Thu 09:07 $ListView_GetItem_0[4]: 0 2023-12-14 Thu 09:07 $ListView_GetItem_0[5]: 0 2023-12-14 Thu 09:07 $ListView_GetItem_0[6]: 0 2023-12-14 Thu 09:07 $ListView_GetItem_0[7]: 0 However Local $Index $Index = _GUICtrlListView_FindText($hListView,$ListViewFindText) Is still returning an Index of -1 So, I have tried using $ListView_GetItem_0 = _GUICtrlListView_GetItem($hListView,0) Instead to see what AutoIt can see, but the returned array is empty. If my code looks OK, then it seems like maybe the _GUICtrlListView UDF won't work with this control. What other UDF's could I try? Link to comment Share on other sites More sharing options...
argumentum Posted December 13, 2023 Share Posted December 13, 2023 have you looked/tried at ControlListView() ? VeeDub 1 Follow the link to my code contribution ( and other things too ). FAQ - Please Read Before Posting. Link to comment Share on other sites More sharing options...
VeeDub Posted December 14, 2023 Author Share Posted December 14, 2023 1 hour ago, argumentum said: have you looked/tried at ControlListView() ? Not yet, but I will. Thanks argumentum 1 Link to comment Share on other sites More sharing options...
VeeDub Posted December 14, 2023 Author Share Posted December 14, 2023 Hello, ControlListView() works! $FILES[0][0] = "viBoot - FS1-110-110.mrimg" Local $ListViewFindText = $FILES[0][0] Local $hWindow = WinGetHandle("Macrium viBoot - Hyper-V") UpdateEventLog("$hWindow: " & $hWindow) Local $hListView = ControlGetHandle($hWindow, "", "[CLASS:SysListView32; INSTANCE:2]") UpdateEventLog("$hListView: " & $hListView) Local $Index $Index = ControlListView($hWindow,"",$hListView,"FindItem",$ListViewFindText) UpdateEventLog("ListViewFindText: " & $ListViewFindText) UpdateEventLog("Index: " & $Index) Sleep(1000) ; Click Virtual Machine _GUICtrlListView_ClickItem($hListView,$Index,"right",True,1) The application that I am working with is a 64 bit application. Up until now I have been compiling my code as x86 For ControlListView to work, I have to compile as x64 However, once the Index is obtained, all the rest of the existing code in this function worked fine. Hopefully switching to x64 won't break any of the other code, I guess I will find out soon enough. @argumentum A big thanks for your help 😀 I don't do a lot of GUI programming, so I don't know all the UDF's. Knowing what to try is half the battle. argumentum 1 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