這是來自於sanhen的一篇發文
不知是否有高手可以幫忙解釋設計思路及語法說明,先謝謝了。#Include <array.au3>
Global $avCtrlList[1] = [0]
$Title = "AutoIt Help"
$Text = ""
$ClassNames = _WinGetClassNameList($Title, $Text)
ConsoleWrite($ClassNames)
;==================================================
; Function _WinGetClassNameList()
; Returns a string containing a list of all ClassNameNN control IDs in a window.
; On success returns all ClassNameNN's in a string delimited by @LF.
; On failure returns 0 and sets @error.
;==================================================
Func _WinGetClassNameList($sWinTitle = "", $sWinText = "")
Local $c, $NN, $hCtrl
; Get list of classes in the window
Local $sClassList = WinGetClassList($sWinTitle, $sWinText)
If @error Then Return SetError(1, 0, 0)
Local $avClassList = StringSplit($sClassList, @LF)
; Try different values of NN
$sClassList = ""
For $c = 1 To $avClassList[0]
$NN = 1
While 1
$hCtrl = ControlGetHandle($sWinTitle, $sWinText, $avClassList[$c] & $NN)
If @error Then
ExitLoop
Else
$sClassList &= $avClassList[$c] & $NN & @LF
$NN += 1
EndIf
WEnd
Next
Return $sClassList
EndFunc ;==>_WinGetClassNameList
Global $Array = _WinGetCtrlInfo(WinGetTitle($Title))
Global $sOne = '[0][0] = ' & $Array[0][0] & @CR, $sTwo
For $iCC = 1 To $Array[0][0]
$sOne &= '[' & $iCC & '][0] = ' & $Array[$iCC][0] & @CR
$sTwo &= '[' & $iCC & '][1] = ' & $Array[$iCC][1] & @CR
Next
MsgBox(64, 'WinInfo', StringTrimRight($sOne, 1) & @CR & StringTrimRight($sTwo, 1))
Func _WinGetCtrlInfo($hWin)
If IsString($hWin) Then $hWin = WinGetHandle($hWin)
Local $sClassList = WinGetClassList($hWin), $iAdd = 1, $aDLL, $sHold
Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
For $iCount = $aSplitClass[0] To 1 Step - 1
Local $nCount = 0
While 1
$nCount += 1
If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop
If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then
$sHold &= $aSplitClass[$iCount] & $nCount & Chr(1)
$iAdd += 1
ReDim $aReturn[$iAdd][2]
$aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount
$aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount))
If @error = 0 Then
$aReturn[$iAdd - 1][1] = $aDLL[0]
Else
$aReturn[$iAdd - 1][1] = ''
EndIf
EndIf
WEnd
Next
$aReturn[0][0] = $iAdd - 1
Return $aReturn
EndFunc ;==>_WinGetCtrlInfo()
|