-1

I want to get text from a dialog box. I am getting the title from the dialog box using winGetTitle() function.

My code in autoit is as follows:

$pId = Run("C:/foldername/Dialogbox.exe")

Local $hWnd   = WinWait("[CLASS:#32770]", "", 10)
Local $sTitle = WinGetTitle("[ACTIVE]")

; Display the window title.
ConsoleWrite($sTitle & @CRLF)

; changing control from the class containg title to the class containing the text. 
Local $hSysTray_Handle = ControlGetHandle('[Class:#32770]', '', '[Class:SysListView32;Instance:1]')
Local $sText           = WinGetText("[ACTIVE]")
Local $sTextnew        = ControlGetText($hSysTray_Handle, "", $sText)

ConsoleWrite($sTextnew & @CRLF)

This returns only the title and not the text in the dialog box. #32770 is the main class of dialog box and title, text are in the different classes in basic control info in autoit.

I am new to autoit and don't know how to fetch the text from dialog box. Or should I use sikuli for this?

Prachi
  • 11
  • 4

1 Answers1

0
; Start Mp3tag if not running.
If Not ProcessExists('Mp3tag.exe') Then
    Run('"C:\Program Files (x86)\Mp3tag\Mp3tag.exe"')
    If @error Then Exit 1
EndIf

; Scans working directory for Mp3 files.
WinWaitClose('Reading directory', '', 5)

; Main window.
$hWnd = WinWait('Mp3tag')

; Get item count of 1st column from the listview.
For $i1 = 1 To 5
    $iCount = ControlListView($hWnd, '', 'SysListView321', 'GetItemCount')

    If $iCount Then
        ConsoleWrite('Found ' & $iCount & ' items.' & @CRLF)
        ExitLoop
    EndIf

    Sleep(1000)
Next

If Not $iCount Then
    MsgBox(0x40000, @ScriptName, 'Count is 0')
    Exit 1
EndIf

; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
    $sText = ControlListView($hWnd, '', 'SysListView321', 'GetText', $i1)
    ConsoleWrite(StringFormat('%3d  Text: %s', $i1, $sText) & @CRLF)
Next

I do not have "C:/foldername/Dialogbox.exe" to test with. I do have Mp3tag which has a SysListView32 control.

ControlListView() can get text etc. from a ListView control. The parameter GetItemCount will get the count of list items and GetText will get text from each list item.

This is test output:

Found 15 items.
  0  Text: 01 - Lively Up Yourself.mp3
  1  Text: 02 - Soul Rebel.mp3
  2  Text: 03 - Treat Yourself Right.mp3
  3  Text: 04 - Rebels Hop.mp3
  4  Text: 05 - Soul Almighty.mp3
  5  Text: 06 - Kaya.mp3
  6  Text: 07 - Trenchtown Rock.mp3
  7  Text: 08 - Soul Shakedown Party.mp3
  8  Text: 09 - Natural Mystic.mp3
  9  Text: 10 - Fussing And Fighting.mp3
 10  Text: 11 - African Herbsman.mp3
 11  Text: 12 - Keep On Moving.mp3
 12  Text: 13 - Go Tell It On The Mountain.mp3
 13  Text: 14 - How Many Times.mp3
 14  Text: 15 - Bonus Track.mp3

The list item number is on the left and the list item text is on the right, following Text:.


At a guess, the code to test your Dialogbox.exe with:

Run("C:\foldername\Dialogbox.exe")
$hWnd = WinWait("[CLASS:#32770]", "", 10)

; Allow time for SysListView321 to fully load.
Sleep(1000)

; Get the window title.
$sTitle = WinGetTitle("[ACTIVE]")
ConsoleWrite($sTitle & @CRLF)

; Changing control from the class containing title to the class containing the text.
$hLView = ControlGetHandle($hWnd, '', 'SysListView321')

; Get item count of 1st column from the listview.
$iCount = ControlListView($hWnd, '', $hLView, 'GetItemCount')

; Get text of each listview item in the 1st column.
For $i1 = 0 To $iCount -1
    $sText = ControlListView($hWnd, '', $hLView, 'GetText', $i1)
    ConsoleWrite(StringFormat('%3d  Text: %s', $i1, $sText) & @CRLF)
Next

It could use some improvement even if it works.

Community
  • 1
  • 1
michael_heath
  • 5,262
  • 2
  • 12
  • 22
  • Thanks for the answer. But the above code is not working. It is not giving any output on - ConsoleWrite(StringFormat('%3d Text: %s', $i1, $sText) & @CRLF) line. There is text in SysListView32 class in the dialog box, but it is not selectable. Also the autoit tool does not provide any information like visible, hidden text except the class SysListView32 and instance 1. – Prachi Jan 05 '19 at 16:33
  • The *Window Info Tool* cannot reasonably read inner text from complex controls such as *ListViews*, *Treeviews* etc. as it would be complex programming to achieve it with a very complex display to show the information, which may not be useful as is, as you need complex programming to access it. As for simple controls such as Edit or Buttons, that is available to display and to read with `ControlGetText()`. The code may need a `Sleep(1000)` or more time after the `WinWait()` as a ListView can take time to be fully loaded with data and to be ready for reading. – michael_heath Jan 06 '19 at 00:20
  • As for better debugging, consider use of `$sTitle = WinGetTitle($hWnd)` instead of `$sTitle = WinGetTitle("[ACTIVE]")` so you are getting the title from the window handle of `$hWnd` which is used later. – michael_heath Jan 06 '19 at 09:56
  • Thanks for the help. The value of $iCount variable is coming as 0. So, it is not taking any text from the dialog box in SysListView32 class. I guess it is a complex dialog box I was testing on. – Prachi Jan 06 '19 at 18:35