0
我有一個GUI,它記錄了文件夾中所有chm的列表。當單擊「運行」按鈕時,它將打開列表中的第一個chm,直到如此。然後我創建了一個應該展開樹的函數。Autoit:創建一個函數?
我的問題是我的功能,它的工作,直到MsgBox()
,並在那裏停止。當我運行我的程序時,沒有顯示錯誤。
#include <GuiConstantsEx.au3>
#include <GuiListBox.au3>
#include <GuiTreeView.au3>
#include <File.au3>
#include <Array.au3>
;GUI
$guiTitle = "Automation"
GUICreate($guiTitle, 250, 430)
Global $hWnd = ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]", "", "[CLASS:SysTreeView32; INSTANCE:1]")
Global $hChild = _GUICtrlTreeView_GetFirstChild($hWnd, 0)
Local $source = InputBox("Source Folder","Please enter the source folder","")
;InputBox
If @error = 1 Then
Exit
EndIf
If @error = 4 Then
Exit
;GUI_List
Else
$add = GUICtrlCreateButton("Show", 10, 53, 230, 20)
$picList = GUICtrlCreateList("", 10, 78, 230, 300)
$run = GUICtrlCreateButton("Run", 170, 385, 70, 30)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Switch $msg
;add
Case $add
Global $FileList = _FileListToArray($source, "*.chm")
If @error = 1 Then
MsgBox(0, "", "No Files Found.")
Exit
EndIf
If @error = 4 Then
MsgBox(0, "", "No Files Found.")
Exit
EndIf
For $i = 1 To $FileList[0] ;List_IFIX Pictures
GUICtrlSetData($picList, $FileList[$i])
Next
;run
Case $run
If _GUICtrlListBox_GetCount($picList) = 0 Then
MsgBox(0, "", "No Files Found.")
Else
For $i = 1 To $FileList[0]
If Not WinExists("AutoIT Help]") Then
ShellExecute($source & "\" & $FileList[1])
_Expand($hWnd, $hChild)
EndIf
Next
EndIf
;exit
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
EndIf
這裏是我的功能:
Func _Expand($hWnd, $hChild)
WinWaitActive("AutoIT Help")
MsgBox(0,"","Expand")
While 1
$hChild = _GUICtrlTreeView_GetNextChild($hWnd, $hChild)
If _GUICtrlTreeView_GetText($hWnd, $hChild) = "Tutorials" Then ExitLoop
WEnd
_GUICtrlTreeView_Expand(ControlGetHandle("[CLASS:HH Parent;TITLE:AutoIt Help]","", "[CLASS:SysTreeView32; INSTANCE:1]"),$hchild, True)
EndFunc
沒有顯示錯誤?那麼語法肯定是無效的,我可以在一行中看到沒有'Next'和'Else Exit'的'For'。您提供的代碼片段在傳遞給_Expand時不會顯示'$ hChild'的值。 – Matt
'WinWaitActive(「[CLASS:AcrobatSDIWindow]」)'有可能永遠等待嗎?嘗試把'WinActive(「[CLASS:AcrobatSDIWindow]」)(或WinActivate或什麼函數名稱,我不記得) – DanFromGermany
我削減了一些線。我只是現在編輯它,並改變文件打開.chm而不是.pdf – NullReferenceException