Thursday 15 January 2015

Autoit: Creating a Function? -


I have a GUI that records the list of all the CMs in a folder. When the 'run' button is clicked, it will open the first CHM in the list. Then I have created a function that should extend the tree.

My problem is my job, it works up to MsgBox () and stops there. When I run my program, the signal is not given.

  #include & lt; GuiConstantsEx.au3 & gt; # Include & lt; GuiListBox.au3 & gt; # Include & lt; GuiTreeView.au3 & gt; # Include & lt; File.au3 & gt; # Include & lt; Array.au3 & gt; ; GUI $ guiTitle = "Automation" GUICreate ($ guiTitle, 250, 430) Global $ hWnd = ControlGetHandle ("[Class: HH Generator; Title: AutoIt Help]", "", "[Class: SysTreeView32, Example: 1]" Enter global $ hChild = _GUICtrlTreeView_GetFirstChild ($ hWnd, 0) local $ source = InputBox ("source folder", "source folder", ""), InputBox then @error = 1 then exitif then @error = 4 then Exit; GUI_List or $ 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 to msg; Enter $$ Global $ file list = _FileListToArray ($ source, "* .chm") If @error = 1 then exit MsgBox (0, "", "no files were found.") If the endfinder @ferror = 4 then MSBBC (0, "", "no file was found.") Exit the INIF $ i = 1 $ file list for [0]; List_FIX image GUICtrlSetData ($ PicList, $ filelist [$ i]) Next; Run Case $ Run if the _GUICtrlListBox_GetCount ($ picList) = 0 then MsgBox (0, "", "no files were found.") Otherwise $ i = 1 to $ file list [0] If not WinExists ("AutoIT Help") Then ShellExecute ($ Source & amp; "\" & Amp; $ FileList [1]) _Expand ($ hWnd, $ hChild) endif Next Endif; Exit Case $ GUI_EVENT_CLOSE ExitLoop EndSwitch going endif   

And here's my function:

  function _Expand ($ hWnd, $ hChild) WinWaitActive ("AutoIt help If the _GUICtrlTreeView_GetText ($ hWnd, $ hChild) = "Tutorials" then exit ExitLoop _GUICtrlTreeView_Expand (ControlGetHandle ("[Class]"), while MsgBox (0, "", "Extension"), while 1 $ hChild = _GUICtrlTreeView_GetNextChild ($ hWnd, $ hChild) : HH Generator; Title: AutoIt Help] "," "," [Class: SysTreeView32, Example: 1] "), $ hchild, True) EndFunc    

Many problems with the code.

  1. Check out your titles! In two instances, you have a spelling of the window title in your example. AutoIt is spelled with a lowercase t , and the window title match is case sensitive if you do not set one option otherwise.
  2. If "tutorial" is not found, you will always be able to loop forever to see that you have reached the end of the tree view, you should add a check after _GUICtrlTreeView_GetNextChild .

    But the real problem with your code is that you are setting the code $ hWnd and $ h child As a result, the window is not found before running the window-making process, and when you call _Expand then $ HWND will always be taped.

    Such a question has not been encouraged on the stack overflow, we get queries that will be useful for others in the future, rather than helping with a specific code. Before asking such questions in the future, please try and debug the problem yourself, you can add the ConsoleWrite statement through the shown value of variable value, which shows you that when you expand , Then there is no handle value of $ hWnd , from there it is clear

No comments:

Post a Comment