Hi,
I am facing with a major issue. It annoys me because I do not understand the background of it.
Long story short:
I have a project which is running perfectly when I run it from ISN AutoIt Studio. But if I run it from SciTE (I think it is the bundled version comes with the AutoIt installer), from Visual Studio Code with AutoIt extension (by Damien, v1.0.5), or compile and run as .exe, it will not run properly.
Long story long:
I would like to test a DotNet application, I have two .au3 files right now.
In the Utils.au3 I have a method which finds a TreeView element by it's name.
#pragma compile(Console, true)
#include <GUIConstantsEx.au3>
#include <GuiTreeView.au3>
Func OpenMenuByFullName($ElementToFind, $click = True)
Local $hWnd = "[REGEXPTITLE:(?i)(.*MyApp\.NET Main Window.*)]"
WinActivate($hWnd)
Local $TreeName = "[NAME:treeViewMenu]" ;~ This could be: "[CLASSNN:WindowsForms10.SysTreeView32.app.0.d0d20b_p5_aa11]"
Local $TreeHandler = ControlGetHandle($hWnd, "", $TreeName)
Global $FindTreeElement = _GUICtrlTreeView_FindItemEx($TreeHandler, $ElementToFind, False)
Local $SelectTreeElement = _GUICtrlTreeView_SelectItem($TreeHandler, $FindTreeElement)
Sleep(500)
; Open selected menu element
If $click Then
_GUICtrlTreeView_ClickItem($TreeHandler, $FindTreeElement, "", "", 2)
Sleep(3000)
Else
Return $FindTreeElement
EndIf
EndFunc
test.au3's purpose in this example is to open MenuElement9 and all children elements. If I get an error during opening child element, $nERR will be incremented by 1, if child element opens successfully $nOK will be incremented by 1.
At the end of the script it writes the number of OKs and errors.
#pragma compile(Console, true)
#include <GuiTreeView.au3>
#include <String.au3>
#include <ScreenCapture.au3>
#include "Utils.au3"
Local $FindTreeElement
Local $MenuArray = ["MenuElement1", "MenuElement2", "MenuElement3", "MenuElement4", "MenuElement5", "MenuElement6", "MenuElement7", "MenuElement8", "MenuElement9", "MenuElement10"]
Local $MenuName = $MenuArray[8]
OpenMenuByFullName($MenuName, False)
$sAll = _TreeView_GetAll('[REGEXPTITLE:(?i)(.*MyApp\.NET Main Window.*)]', '', '[NAME:treeViewMenu]', $MenuName)
Func _TreeView_GetAll($title, $text, $classNN, $menu, $collapse = True)
$sAll = ''
$hWnd = ControlGetHandle($title, $text, $classNN)
WinActivate($title)
If $collapse Then _GUICtrlTreeView_Expand($hWnd, 0, False) ; Collapse All
$hItem = $FindTreeElement
$i = 1
While $hItem <> 0x00000000
$sItem = _GUICtrlTreeView_GetTree($hWnd, $hItem)
$sItemSplit = StringSplit($sItem, "|")
Local $nOK
Local $nERR
If $sItemSplit[1] = $menu Then
_GUICtrlTreeView_SelectItem($hWnd, $hItem)
_GUICtrlTreeView_ClickItem($hWnd, $hItem, "", "", 2)
Sleep(2000)
;~ ***some other magic***
Else
ConsoleWrite(@CRLF & "------------------------------------------------" & @CRLF)
ConsoleWrite($MenuName & " test finished." & @CRLF)
ConsoleWrite("OK: " & $nOK & @CRLF & "ERR: " & $nERR)
Sleep(500)
Exit (20)
EndIf
WEnd
Return $sAll
EndFunc
As I observed, if I use SciTE/VSC/compiled .exe, $FindTreeElement's value did not pass from Utils.au3 to test.au3. $FindTreeElement's value is 0x0000000000000000 in test.au3, so the While loop will be skipped.
What am I not noticing? Why is this code working in ISN AIS, and why not working in other Editors / command line?