从使用的AutoIt对话框获取特定的文本

问题描述 投票:-1回答:1

我想从一个对话框文本。我从使用对话框winGetTitle()功能获得冠军。

我在AutoIt的代码如下:

$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)

这只返回的称号,而不是在对话框中的文本。 #32770是主类对话框,标题,文字是在AutoIt的基本控制信息的不同类别。

我是新来的AutoIt,不知道如何来从对话框中的文本。或者我应该使用sikuli这个?

autoit
1个回答
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

我没有"C:/foldername/Dialogbox.exe"来测试。我有Mp3tag具有SysListView32控制。

ControlListView()可以从ListView控件获取文本等。参数GetItemCount将得到的列表项目的数量和GetText会得到来自各列表项的文本。

这是测试输出:

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

列表项数是在左边,列表项的文字是在右边,以下Text:


在猜测,该代码与测试Dialogbox.exe

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

它可以使用一些改进,即使它的工作原理。

© www.soinside.com 2019 - 2024. All rights reserved.