dd1978 Posted January 23, 2023 Share Posted January 23, 2023 take a look at following code: Func Example_01() # I copy properties of win form and control by AutoIt window info tool Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]" Local $ctl_ppt = "[CLASS:WindowsForms10.LISTBOX.app.0.141b42a_r9_ad1;NAME:ListBox1;INSTANCE:1]" WinActivate($win_ppt, "") Local $ret = ControlCommand($win_ppt, "", $ctl_ppt, "AddString", 'line ii') If @error Then MsgBox($MB_SYSTEMMODAL, "", "Error") EndIf EndFunc #==>Example_01 The result of running the code is: get error and no new line is added to ListBox Anyone can help, thanks. Link to comment Share on other sites More sharing options...
ioa747 Posted January 23, 2023 Share Posted January 23, 2023 (edited) 4 hours ago, dd1978 said: Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]" that doesn't seem right in info Tools in the Windows tab it does not have Advanced mode as have the control tab [TITLE:My Window; CLASS:My Class; INSTANCE:2] ... and the # I copy properties of win form and control by AutoIt window info tool is better with ; I copy properties of win form and control by AutoIt window info tool Edited January 23, 2023 by ioa747 I know that I know nothing Link to comment Share on other sites More sharing options...
dd1978 Posted January 24, 2023 Author Share Posted January 24, 2023 but by using the mode, the code that do clicking a button on a windows form can work correctly. thanks. Link to comment Share on other sites More sharing options...
ioa747 Posted January 24, 2023 Share Posted January 24, 2023 try first to minimize, to see if you have the right handle WinSetState($win_ppt, "", @SW_MINIMIZE) I know that I know nothing Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 in the code I post above, WinActivate($win_ppt, "") this line really brings the window to front. Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 I just test the code that minimize and maximize the windows form by WinSetState function, it does a correct action. Link to comment Share on other sites More sharing options...
ioa747 Posted January 25, 2023 Share Posted January 25, 2023 try something like Local $Test = ControlGetText($win_ppt, "", "ListBox1") ConsoleWrite("$Test=" & $Test & @CRLF) $Test = ControlGetHandle($win_ppt, "", "ListBox1") ConsoleWrite("$Test=" & $Test & @CRLF) to interact with control, to be sure you have the right control handle I know that I know nothing Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 I have tested following code: Func Example_01() Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]" Local $hWnd = WinGetHandle($win_ppt) If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the window handle.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", $hWnd) EndFunc ;==>Example_01 The MsgBox prints the value: 0x000306A2 and without error I feel that this is a handle, right? Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 well above code is for win form I am now trying to get control handle Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 I have tested the code for control: Func Example_02() Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1;INSTANCE:1]" Local $ctl_ppt = "[CLASS:WindowsForms10.LISTBOX.app.0.141b42a_r9_ad1;NAME:ListBox1;INSTANCE:1]" Local $hControl = ControlGetHandle($win_ppt, "", $ctl_ppt) If @error Then MsgBox($MB_SYSTEMMODAL, "", "An error occurred when trying to retrieve the control handle.") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", "The handle is: " & $hControl) EndFunc ;==>Example_02 has run without error MsgBox prints the value of $hControl like a handle: 0x000E0610 any suggestions, thanks Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 The UI to be tested against is a .net winform. I compile the UI application under VS2019 VB.Net I have tested button click, button enable and disable, combo box show dropdown and hide dropdown. These tasks all work properly. Now I stoped at using AddString command of ControlCommand function to add new line into ListBox. Is there any configuration required for ListBox to get new line from my AutoIt script? Link to comment Share on other sites More sharing options...
ioa747 Posted January 25, 2023 Share Posted January 25, 2023 not that I know try to get some value from control Local $Test = ControlCommand($win_ppt, "", $ctl_ppt , "GetCount", "") ConsoleWrite("$Test=" & $Test & @CRLF) I know that I know nothing Link to comment Share on other sites More sharing options...
ioa747 Posted January 25, 2023 Share Posted January 25, 2023 try this format Local $Test = ControlCommand($win_ppt, "", "[NAME:ListBox1]" , "GetCount", "") ConsoleWrite("$Test=" & $Test & @CRLF) I know that I know nothing Link to comment Share on other sites More sharing options...
dd1978 Posted January 25, 2023 Author Share Posted January 25, 2023 There is not GetCount command for ListBox control, and I found "GetLineCount" command for Edit control Thanks. Link to comment Share on other sites More sharing options...
dd1978 Posted January 27, 2023 Author Share Posted January 27, 2023 has answer? Link to comment Share on other sites More sharing options...
Nine Posted January 28, 2023 Share Posted January 28, 2023 Quote "GetCount", "" Returns number of entries in a ListBox or ComboBox About ControlCommand in help file. Make sure you have latest version of AutoIt. ioa747 1 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
ioa747 Posted January 28, 2023 Share Posted January 28, 2023 @Nine Thank you for the explanation @dd1978 I honestly don't know. I just try to help from help book see Title special definition e.g. Set the text of the .NET Winforms "textBoxFolder" control to "C:\Some\Folder" ControlSetText("My Window", "", "[NAME:textBoxFolder]", "C:\Some\Folder") I know that I know nothing Link to comment Share on other sites More sharing options...
dd1978 Posted January 28, 2023 Author Share Posted January 28, 2023 @Nine thanks. it is actually a too old version I am using. I would try the newest one @ioa747 thanks a lots for these days help. Link to comment Share on other sites More sharing options...
dd1978 Posted January 31, 2023 Author Share Posted January 31, 2023 @Nine@ioa747I'm back, with problem testing result I have install the latest stable version of AutoIt, then run the following code: Func Example_03() Local $win_ppt = "[TITLE:Form_ListBox;CLASS:WindowsForms10.Window.8.app.0.141b42a_r9_ad1]" Local $ctl_ppt = "[NAME:ListBox1]" Local $hWnd = WinActivate($win_ppt, "") Local $Test = ControlCommand($hWnd, "", $ctl_ppt , "GetCount", "") If @error Then MsgBox($MB_SYSTEMMODAL, "", "Error") Exit EndIf MsgBox($MB_SYSTEMMODAL, "", $Test) EndFunc The last MsgBox print: -1 no error occurs My ListBox1 has three items before I run the code. In this forum, I found somebody advise to use beta version and is it an answer? Thanks. Link to comment Share on other sites More sharing options...
dd1978 Posted January 31, 2023 Author Share Posted January 31, 2023 And by my test, command "AddString" for ControlCommand still cause error 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