Sign in to follow this  
Followers 0
JVPK

Picking up application error messages

11 posts in this topic

Hi

I have an AutoIT script that picks up the current version of our App and the last release and using a directory full of files ensures that our App is backward and forward compatible. We get a smattering of 'warning messages' as well as error messages. Depending on where I am in the process depends on whether I ignore the message or wait for human assistance. The error and warning messages all have the same window title as the App's main window. The only thing that changes is the text in the box. There is no text in the main App.

I am using the code below and it does not work for one of the messages but I cannot see why... it also does not work if I am on the 1st file in the dirctory...

; Run AxCent 1
            Send("#r")
            WinWaitActive("Run")
            Send($EXE1DirPath)
            Send("{ENTER}")
    While 1
        $selfile = FileFindNextFile($search) 
        If @error Then ExitLoop
     
        
        ; Wait for AxCent to become active
            WinWaitActive("AxCent")
            
        ; Open first DES file
            Send("!F, O")
            WinWaitActive("Open")
            Send($DESDirPathOrig)
            Send("{ENTER}")
            Send("{DEL}")
            WinWaitActive ("Open")
            Send($selfile, 1)
            Send("{ENTER}")
            
        ;Wait for AxCent window to become active
            WinWaitActive("AxCent")
            If WinActive("AxCent","The CFD") then
                Send("{ENTER}")
            EndIf
            ;Save the file to Axcent version numbered directory 
            WinActivate("AxCent")
            Send("!F, A")
            WinWaitActive("Save As")
            Send($Version1Path & "\" & $selfile)
            Send("{ENTER}")
            Send("!F, C")
            

    Wend

message1.jpg - The error message that seems to be handled OK:

message2.jpg - The error message that gets ignored.

I really can't see why 1 is handled and 2 is not...

Thanks

John

post-57040-12713625061381_thumb.jpg

post-57040-12713625208264_thumb.jpg

Share this post


Link to post
Share on other sites



I assume this is not all the code as I could not get it to compile. As there is no indercation what $search is I cannot answer why it does not work on the first directory. Can you provide more informaiton on that?

What do you mean by error and warning messages?

Using ControlGetText() you will able to read the text from the text box, from there you can use StringInStr to differentiate between the two message boxes. See whichMsgBox() below.

; Run AxCent 1
Send("#r")
WinWaitActive("Run")
Send($EXE1DirPath)
Send("{ENTER}")
While 1
    $selfile = FileFindNextFile($search)
    If @error Then ExitLoop

    ; Wait for AxCent to become active
    WinWaitActive("AxCent")

    ; Open first DES file
    Send("!F, O")
    WinWaitActive("Open")
    Send($DESDirPathOrig)
    Send("{ENTER}")
    Send("{DEL}")
    WinWaitActive("Open")
    Send($selfile, 1)
    Send("{ENTER}")

    ;Wait for AxCent window to become active
    WinWaitActive("AxCent")
    If WinActive("AxCent", "The CFD") Then
        Send("{ENTER}")
        whichMsgBox() ; test what is returned.
    EndIf
    ;Save the file to Axcent version numbered directory
    WinActivate("AxCent")
    Send("!F, A")
    WinWaitActive("Save As")
    Send($Version1Path & "\" & $selfile)
    Send("{ENTER}")
    Send("!F, C")
WEnd

Func whichMsgBox()
    Local $string = ControlGetText('AxCent', 'The CFD', "") ; use the autoit info tool to complete. Test the return to ensure if it is valid.
    ; If you have issues use ControlGetHandle to test your params.
    If StringInStr($string, 'Access Violation') <> 0 Then
        Return 1 ; first message box is displayed.
    ElseIf StringInStr($string, 'Out of Memory') <> 0 Then
        Return 2 ; second message box is displayed
    Else
        SetError(1, 0, 0)
        Return 0 ; something went wrong.
    EndIf

EndFunc   ;==>whichMsgBox

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Thanks for looking at it.

$search is set by:

$search = FileFindFirstFile($DESDirPath)
                            
; Check if the search was successful
If $search = -1 Then
   MsgBox(0, "No DES Files Found in:", $DESDirPath)
   GUICtrlSetData(12, "")                                   
EndIf

This is all of $search prior history. $DESDirPath is a directory entry from the gui. I could post the whole thing but without AxCent app it wouldn't run anyway...

"What do you mean by error and warning messages?" - The two attachments to the first post contain examples of 2 messages put out by the AxCent application. Depending on when I get them in the testing process determines whether I treat them as a stop program event, error, or a ignore and continue, warning.

I may be able to use the function you suggested but not where you have it, my main/first problem is that the line:

If WinActive("AxCent", "The CFD") Then

Doesn't actually recognize the second of the message strings, ie the one with 'Out of memory' in it despite the fact that it appear to be titled AxCent and the first part of the text is "The CFD".

When I use 'Window Info' I get this as my window text for message 1:

OK

The CFD data or other embedded data could not be read from the file.

Most likely this file was created by a newer version of AxCent.

The design that was read might not be usable.

[unexpected [Access violation [r] at 41624f43] error happened.

The application may become unstable.

It is recommended to save your documents and restart the application.]

And this as my text for message 2:

OK

The CFD data or other embedded data could not be read from the file.

Most likely this file was created by a newer version of AxCent.

The design that was read might not be usable.

[MFC memory error

Out of memory.]

That 'winactive' line seems to pick up 1 but not 2... I can't see why.

Thanks again

John

PS if you want the whole script as it stands here goes:

; Include necessary GUI Constants
    #include <GUIConstants.au3>
    #include <GUIButton.au3>
    #include <GUIListBox.au3>
    #include <Date.au3>
    
; Tell GUI controller to base user input on monitored events
    Opt("GUIOnEventMode", 0)

; Set GUI coordinate mode options - use absolute positioning
    Opt("GUICoordMode", 1)  
    
; Variables initialization

$DESDirPath = "C:\Program Files (x86)\Concepts\QA_Files"    
$EXEDirPath = "C:\Program Files (x86)\Concepts\AxCent\"
$ExeDirPath = "C:\Program Files (x86)\Concepts\AxCent\"


; Detect OS version to eliminate OS dependency
    $OSVer = @OSVersion

; ======================= GUI for Page #1: QA Tool - Select Actions ===================================

; Create the window and assign it to a variable for later use
    $1 = GUICreate ("QA Tool", 500, 370)
    
    ; Welcome text at top of window
        GUICtrlCreateLabel ("WELCOME TO THE QA TOOL. SELECT DIRECTORIES:", 10, 10)

    ; Set the directory to the new version of AxCent
        GUICtrlCreateLabel ( "AxCent Previous Release:", 10, 30)                    
            ; Make path entry bar
                GUICtrlCreateInput("", 10, 50, 425, 20)
            ; Make browse button
                $BrowseEXE1DirPressed = GUICtrlCreateButton ("...", 445, 50, 30, 20)
                
    ; Set the directory for the last release of AxCent
        GUICtrlCreateLabel ("AxCent Current Beta:", 10, 80)
            ; Make path entry bar
                GUICtrlCreateInput("", 10, 100, 425, 20)
            ;Make browse button
                $BrowseEXE2DirPressed = GUICtrlCreateButton ("...",445,100,30,20)
    ; Just a line
        GUICtrlCreateLabel ("________________________________________________________________________________________",0,140)
    
    ; Set the directory for QA Tool to get DES files
        GUICtrlCreateLabel ( "Select test directory containing DES files:", 10, 170)                    
            ; Make path entry bar
                GUICtrlCreateInput("", 10, 190, 425, 20)
            ; Make browse button
                $BrowseDESDirPressed = GUICtrlCreateButton ("...", 445, 190, 30, 20)
            
                    
    ; Create the Run button
        $Run = GUICtrlCreateButton ("Run", 310, 340, 60, 20)
            
    ; Create the Exit button
        $Exit = GUICtrlCreateButton ("Exit", 150, 340, 60, 20)

; ===============================================================================================================           

                
    
While 1 ; ######################################## Main UI Loop #################################################

Dim $date1[6], $date2[6], $datetemp[6]

    ; Start monitoring for user input, create switch structure
    
    GUISwitch($1)
        GUISetState()
        Do      
            GUISetState(@SW_SHOW, $1)
            $msg = GUIGetMsg()  

    ; ======================= LOGIC for Page #1: Export Tool - Select Actions ==================================
            
            ; Define variables based on UI
            
                        If $msg = $BrowseEXE1DirPressed Then
                        
                            $EXE1Dir = FileSelectFolder ( "Select Folder:", "" , 1 , "C:\Program Files (x86)\Concepts\" )
                            GUICtrlSetData(5, $EXE1dir, "C:\Program Files (x86)\Concepts\AxCent\")
                            
                            ; We need the original path for later use, so we preserve it in its own variable before modifying
                            $EXE1DirPathOrig = GUICtrlRead (5)
                            
                            ; \axcent.exe is added for later use with FileFindFirstFile function
                            GUICtrlSetData (5, "\axcent.exe", "C:\Program Files (x86)\Concepts\AxCent" )
                            
                            ; Here, a new variable is initialized containing the modified path information for FileFindFirstFile function   
                            $EXE1DirPath = GUICtrlRead (5)
                            $version1 = FileGetVersion($EXE1DirPath)
                            $date1 = FileGetTime($EXE1DirPath)
                            
                        ElseIf $msg = $BrowseEXE2DirPressed Then
                        
                            $EXE2Dir = FileSelectFolder ("Select Folder:", "" , 1 , "C:\Program Files (x86)\Concepts\" )
                            GUICtrlSetData(8, $EXE2dir, "C:\Program Files (x86)\Concepts\AxCent")
                            
                            ; We need the original path for later use, so we preserve it in its own variable before modifying
                            $EXE2DirPathOrig = GUICtrlRead (8)
                            
                            ; \axcent.exe is added for later use with FileFindFirstFile function
                            GUICtrlSetData (8, "\axcent.exe", "C:\Program Files (x86)\Concepts\AxCent" )
                            
                            ; Here, a new variable is initialized containing the modified path information for FileFindFirstFile function   
                            $EXE2DirPath = GUICtrlRead (8)
                            $version2 = FileGetVersion($EXE2DirPath)
                            $date2 = FileGetTime($EXE2DirPath)
                            
                        ElseIf $msg = $BrowseDESDirPressed Then
                        
                            $DESDir = FileSelectFolder ("Select Folder:", "" , 1 , "C:\Program Files (x86)\Concepts\QA_Files" )
                            GUICtrlSetData(12, $DESdir)
                            
                                
                            
                            ; Here, a new variable is initialized containing the modified path information for FileFindFirstFile function   
                            $DESDirPathOrig = GUICtrlRead (12)
                            ; File Selection Loop - Program looks through chosen directory for DES files
                            GUICtrlSetData(12, "\*.des", "C:\Program Files (x86)\Concepts\QA_Files")
                            $DESDirPath = GUICtrlRead (12)
                
                            $search = FileFindFirstFile($DESDirPath)
                            
                            ;MsgBox(0, "$Search", $Search)

                            ; Check if the search was successful
                            If $search = -1 Then
                                MsgBox(0, "No DES Files Found in:", $DESDirPath)
                                GUICtrlSetData(12, "")                                  
                            EndIf
                                
                                
                            $Version1Path = $DesDirPathOrig & "\" & $version1
                            $Version2Path = $DesDirPathOrig & "\" & $version2
                            DirRemove ($Version1Path,1)
                            DirRemove ($Version2Path,1)
                            DirCreate ($Version1Path)
                            DirCreate ($Version2Path)
                            $Version1FilePath = $Version1Path & "\*.des"
                            $Version2FilePath = $Version2Path & "\*.des"
                            
                                                                                        
                        EndIf
                        
                        
                
                ; Pressing Exit
                    If $msg = $Exit Then
                        Exit
                    EndIf   
    
                ; Pressing "X" close button 
                    If  $msg = $GUI_EVENT_CLOSE Then
                        Exit
                    EndIf   
    
    ; ===============================================================================================================
    until   $msg = $Run
    
    If $msg = $Run Then
            GUISetState(@SW_HIDE, $1) 
            ExitLoop
        EndIf
            
            
Wend ; ######################################## END OF Main UI Loop #################################################   
        
; ############################################# BEGIN Program Modules ###############################################

                            $exedate1=$date1[0] & "/" & $date1[1] & "/" & $date1[2]
                            $exedate2=$date2[0] & "/" & $date2[1] & "/" & $date2[2]
                            $datediff = _DateDiff('D',$exedate1, $exedate2)
                            ;MsgBox(0,"Date diff", $datediff)
                            If $datediff<=0 then
                                $EXETempDir=$EXE2Dir
                                $EXE2Dir=$EXE1Dir
                                $EXE1Dir=$EXETempDir
                                $EXETempDirPathOrig=$EXE2DirPathOrig
                                $EXE2DirPathOrig=$EXE1DirPathOrig
                                $EXE1DirPathOrig=$EXETempDirPathOrig
                                $EXETempDirPath=$EXE2DirPath
                                $EXE2DirPath=$EXE1DirPath
                                $EXE1DirPath=$EXETempDirPath
                                $versionTemp=$version2
                                $version2=$version1
                                $version1=$versionTemp
                                $versionTempPath=$version2Path
                                $version2Path=$version1Path
                                $version1Path=$versionTempPath
                                $versionTempFilePath=$version2FilePath
                                $version2FilePath=$version1FilePath
                                $version1FilePath=$versionTempFilePath
                                $dateTemp=$date2
                                $date2=$date1
                                $date1=$dateTemp
                            EndIf



        ; Run AxCent 1
            Send("#r")
            WinWaitActive("Run")
            Send($EXE1DirPath)
            Send("{ENTER}")
    While 1
        $selfile = FileFindNextFile($search) 
        If @error Then ExitLoop
     
        
        ; Wait for AxCent to become active
            WinWaitActive("AxCent")
            
        ; Open first DES file
            Send("!F, O")
            WinWaitActive("Open")
            Send($DESDirPathOrig)
            Send("{ENTER}")
            Send("{DEL}")
            WinWaitActive ("Open")
            Send($selfile, 1)
            Send("{ENTER}")
            
        ;Wait for AxCent window to become active
            WinWaitActive("AxCent")
            If WinActive("AxCent","The CFD") then
                Send("{ENTER}")
                ;MsgBox(0, "File Failure", $selfile)
                ;MsgBox(0, "AxCent Version", $version1)
                ;Exit
            ElseIf WinActive("AxCent","A suitable document") <> 0 then
                Send("{ENTER}")
                MsgBox(0, "File Failure", $selfile)
                MsgBox(0, "AxCent Version", $version1)
                Exit
            EndIf
                ;Save the file to Axcent version numbered directory 
                WinActivate("AxCent")
                Send("!F, A")
                WinWaitActive("Save As")
                Send($Version1Path & "\" & $selfile)
                Send("{ENTER}")
                Send("!F, C")
            

    Wend                            

            ;Close Axcent
            WinWaitActive ("AxCent")
            Send("!F, X")
 
            
            ; Run AxCent 2
            Send("#r")
            WinWaitActive("Run")
            ;msgbox (0, "Exe2DirPath", $Exe2DirPath)
            Send($EXE2DirPath)
            Send("{ENTER}")
            
            ; See if AxCent 2 will open AxCent 1 files
            ; & "\*.des"
            $search2 = FileFindFirstFile($Version1FilePath)
            
            ;msgbox (0, "Search2", $search2)
            

    While 1
        $selfile2 = FileFindNextFile($search2) 
        If @error Then ExitLoop
     
        
        ; Wait for AxCent to become active
            WinWaitActive("AxCent")
                        
        ; Open first DES file
            Send("!F, O")
            WinWaitActive("Open")
            Send($Version1Path)
            ;msgbox (0, "Version2Path", $Version1Path)
            ;msgbox (0, "FirstFile", $selfile2)
            Send("{ENTER}")
            Send("{DEL}")
            WinWaitActive ("Open")
            Send($selfile2, 1)
            Send("{ENTER}")

        ;Wait for AxCent window to become active
            WinWaitActive("AxCent")
        ;Close the file
            Send("!F, C")
                        
    Wend    
    
            ;Saveas original files in AxCent 2
            ;AxCent is already open
        $search3 = FileFindFirstFile($DesDirPath)

    While 1
        $selfile = FileFindNextFile($search3) 
        If @error Then ExitLoop
     
        
        ; Wait for AxCent to become active
            WinWaitActive("AxCent")
            
        ; Open first DES file
            Send("!F, O")
            WinWaitActive("Open")
            Send($DESDirPathOrig)
            ;msgbox (0, "DesDirPathOrig", $DesDirPathOrig)
            ;msgbox (0, "FirstFile", $selfile)
            Send("{ENTER}")
            Send("{DEL}")
            WinWaitActive ("Open")
            Send($selfile, 1)
            Send("{ENTER}")

        ;Wait for AxCent window to become active
            WinWaitActive("AxCent")
        ;Save the file to Axcent version number directory   
            Send("!F, A")
            WinWaitActive("Save As")
            Send($Version2Path & "\" & $selfile)
            Send("{ENTER}")
            WinWaitActive("AxCent")
            Send("!F, C")
            ;Send("{DEL}")
            ;Send($selfile, 1)
            ;Send("{ENTER}")
            
    Wend
        ;Close Axcent
            WinWaitActive ("AxCent")
            Send("!F, X")
            
        ; Run AxCent 1
            Send("#r")
            WinWaitActive("Run")
            Send($EXE1DirPath)
            Send("{ENTER}")
            
            ; See if AxCent 1 will open AxCent 2 files
            
            $search4 = FileFindFirstFile($Version2FilePath)
            

    While 1
        $selfile3 = FileFindNextFile($search4) 
        If @error Then ExitLoop
     
        
        ; Wait for AxCent to become active
            WinWaitActive("AxCent")
            
        ; Open first DES file
            Send("!F, O")
            WinWaitActive("Open")
            Send($Version2Path)
            ;msgbox (0, "Version2Path", $Version2Path)
            ;msgbox (0, "FirstFile", $selfile3)
            Send("{ENTER}")
            Send("{DEL}")
            WinWaitActive ("Open")
            Send($selfile3, 1)
            Send("{ENTER}")

        ;Wait for AxCent window to become active
            WinWaitActive("AxCent")
        ;Close the file
            Send("!F, C")
                        
    Wend    
    
        ;Close Axcent
            WinWaitActive ("AxCent")
            Send("!F, X")
            
        ;Notify of completion
        MsgBox ( 64, "QA Tool Completed Successfully", "Test cases exhausted")
        Exit

Share this post


Link to post
Share on other sites

So I hacked my script down so that it is just pulling files from a single directory using a single version of the App that I am testing. My code currently looks like this:

; ==============================================================================================================================================================
; 
; AutoIt v 3.3.6
; QATools v 1.0
; Code and program ©2010 Concepts ETI, Inc.
; Coded by John Keeling
; 
;   Part 1: Checks that a new version of AxCent is backwards and forwards compatible with an older version.                                 
;
;  =============================================================================================================================================================    
    
; Variables initialization
$DESDirPathOrig = "C:\Users\jvk\my documents\test"
$DESDirPath = "C:\Users\jvk\my documents\test\*.des"
$EXEDirPath = "C:\Program Files (x86)\Concepts\AxCent\"

$search = FileFindFirstFile($DESDirPath)
                            
If $search = -1 Then
    MsgBox(0, "No DES Files Found in:", $DESDirPath)
    GUICtrlSetData(12, "")                                  
EndIf
; ############################################# BEGIN Program Modules ###############################################

        ; Run AxCent 
    Send("#r")
    WinWaitActive("Run")
    Send($EXEDirPath & "\axcent.exe")
    Send("{ENTER}")
While 1
    $selfile = FileFindNextFile($search) 
    If @error Then ExitLoop
        
    ; Wait for AxCent to become active
    WinWaitActive("AxCent")
        
    ; Open first DES file
    Send("!F, O")
    WinWaitActive("Open")
    Send($DESDirPathOrig)
    Send("{ENTER}")
    Send("{DEL}")
    WinWaitActive ("Open")
    Send($selfile, 1)
    Send("{ENTER}")
        
    ;Wait for AxCent window to become active
    WinWaitActive("AxCent")
    $box = whichMsgBox() 

    If $box = 1 OR $box = 2 then
        Send("{ENTER}")
        MsgBox(0,"1 or 2", $box)
        Send("{ENTER}")
    ElseIf $box = 3 then
        Send("{ENTER}")
        MsgBox(0, "File Failure", $selfile)
        MsgBox(0, "AxCent Version", $version1)
        Exit
    EndIf
        ;Save the file to Axcent version numbered directory 
        WinActivate("AxCent")
        Send("!F, A")
        WinWaitActive("Save As")
        Send($Version1Path & "\" & $selfile)
        Send("{ENTER}")
        Send("!F, C")
    Wend
    
Func whichMsgBox()
    Local $string = ControlGetText("AxCent","","[CLASSNAMENN:Static2]") 
    MsgBox(0, "Text", $string)
    If StringInStr($string, 'Access violation') <> 0 Then
        Return 1 ; first message box is displayed.
    ElseIf StringInStr($string, 'Out of memory') <> 0 Then
        Return 2 ; second message box is displayed
    ElseIf StringInStr($string, 'A suitable document') <> 0 Then
        Return 3
    Else 
        Return
    EndIf
EndFunc   ;==>whichMsgBox

;Close Axcent
WinWaitActive ("AxCent")
Send("!F, X")
;Notify of completion
MsgBox ( 64, "QA Tool Completed Successfully", "Test cases exhausted")
Exit

I have tried all sorts of combinations of ID's, Class, Title, ClassnameNN, Class, Instance etc to try and pick up the text in the message. This is the summary output from AutoIt v3 Window Info:

>>>> Window <<<<

Title: AxCent

Class: #32770

Position: 405, 275

Size: 486, 219

Style: 0x94C801C5

ExStyle: 0x00010101

Handle: 0x00000000000C07A8

>>>> Control <<<<

Class: Static

Instance: 2

ClassnameNN: Static2

Name:

Advanced (Class): [CLASS:Static; INSTANCE:2]

ID: 65535

Text: The CFD data or other embedded data could not be read from the file.

Most likely this file was created by a newer version of AxCent.

The design that was read might not be usable.

[unexpected [Access violation [r] at 41624f43] error happened.

The application may become unstable.

It is recommended to save your documents and restart the application.]

Position: 65, 26

Size: 378, 92

ControlClick Coords: 134, 46

Style: 0x50022080

ExStyle: 0x00000004

Handle: 0x00000000000D073C

>>>> Mouse <<<<

Position: 202, 97

Cursor ID: 0

Color: 0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

OK

The CFD data or other embedded data could not be read from the file.

Most likely this file was created by a newer version of AxCent.

The design that was read might not be usable.

[unexpected [Access violation [r] at 41624f43] error happened.

The application may become unstable.

It is recommended to save your documents and restart the application.]

>>>> Hidden Text <<<<

I have managed to get 0, OK, some text that I cannot find anywhere, text from the main window... in fact just about everything except: "The CFD data or other embedded data could not be read from the file.

Most likely this file was created by a newer version of AxCent.

The design that was read might not be usable.

[unexpected [Access violation [r] at 41624f43] error happened.

The application may become unstable.

It is recommended to save your documents and restart the application.]" WHich is what I want!

Any ideas at all? I am assuming AutoIt can handle a #32770 dialog window? Zero, has been my total productivity for 2 whole days trying to get this to work.

Thanks - John

Share this post


Link to post
Share on other sites

1.) WinActive may only be picking up the first instance of the window, thus the second is never seen.

2.) There is no reason why the first '$search = FileFindFirstFile($DESDirPath)' can't go in the while loop. You can also put the error checking in there -> if $search = -1 and @error.

3.) Please post the output of both windows within a code box.

4.) After you have the handle to the window the only information of importance is the Control info. >>>> Visible Text <<<< is not important. You might be able to use WinGetHandle("[ACTIVE]") after your call to WinWaitActive. This might solve point 1.

5.) I had errors compiling as $version was not declared. I recommend putting ' Use Opt("MustDeclareVars", 1) ' at the top of your script and trying to build.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

1.) WinActive may only be picking up the first instance of the window, thus the second is never seen.

This is possible, I have pulled out the text from the active window and it usually comes out with the text from the main app window... but if I hit return it executes in the message window!

2.) There is no reason why the first '$search = FileFindFirstFile($DESDirPath)' can't go in the while loop. You can also put the error checking in there -> if $search = -1 and @error.

I use it as the seed for 4 different loops, this is only a small part of this script with the GUI stripped from it etc.

3.) Please post the output of both windows within a code box. - The top one is the main window the second one is the message window the final one is the actual text message control I am trying to access on the message window.

>>>> Window <<<<
Title:  AxCent
Class:  Afx:00400000:8:00010003:00000000:067C070D
Position:   -1, 0
Size:   1155, 781
Style:  0x1CCF8000
ExStyle:    0x00000110
Handle: 0x0000000000280B14

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Name:   
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 

>>>> Mouse <<<<
Position:   356, 14
Cursor ID:  0
Color:  0xC6D4E2

>>>> StatusBar <<<<
1:  For Help, press F1
2:  
3:  
4:  NUM
5:  
6:  04/20/10
7:  16:44:49

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
For Help, press F1


>>>> Hidden Text <<<<

>>>> Window <<<<
Title:  AxCent
Class:  #32770
Position:   597, 401
Size:   486, 219
Style:  0x94C801C5
ExStyle:    0x00010101
Handle: 0x00000000004A09CE

>>>> Control <<<<
Class:  
Instance:   
ClassnameNN:    
Name:   
Advanced (Class):   
ID: 
Text:   
Position:   
Size:   
ControlClick Coords:    
Style:  
ExStyle:    
Handle: 

>>>> Mouse <<<<
Position:   196, 14
Cursor ID:  0
Color:  0xBABABA

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]


>>>> Hidden Text <<<<

>>>> Window <<<<
Title:  AxCent
Class:  #32770
Position:   333, 281
Size:   486, 219
Style:  0x94C801C5
ExStyle:    0x00010101
Handle: 0x000000000035059E

>>>> Control <<<<
Class:  Static
Instance:   2
ClassnameNN:    Static2
Name:   
Advanced (Class):   [CLASS:Static; INSTANCE:2]
ID: 65535
Text:   The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]
Position:   65, 26
Size:   378, 92
ControlClick Coords:    90, 33
Style:  0x50022080
ExStyle:    0x00000004
Handle: 0x0000000000640AA0

>>>> Mouse <<<<
Position:   158, 84
Cursor ID:  0
Color:  0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]


>>>> Hidden Text <<<<

4.) After you have the handle to the window the only information of importance is the Control info. >>>> Visible Text <<<< is not important. You might be able to use WinGetHandle("[ACTIVE]") after your call to WinWaitActive. This might solve point 1.

I tried this and got the text from the main window ie "For Help, press F1" see jpg, bottom left corner of main window. I did notice that the message window doesn't seem to have an 'INSTANCE' number.

5.) I had errors compiling as $version was not declared. I recommend putting ' Use Opt("MustDeclareVars", 1) ' at the top of your script and trying to build. - Sorry, it had compiled and run OK for me. What does the option do?

Thanks again - John

post-57040-12717959579078_thumb.jpg

Share this post


Link to post
Share on other sites

1.) WinActive may only be picking up the first instance of the window, thus the second is never seen.

This is possible, I have pulled out the text from the active window and it usually comes out with the text from the main app window... but if I hit return it executes in the message window!

I do not understand is going on where. WinActive should get the handle of the current active window and it should not matter if it is a message box or anything else.

Assuming the WinActive call is successful, WinGetHandle("[ACTIVE]") has to work. I would check to ensure WinActive is working correctly.

Side thought for _WinAPI_WindowFromPoint(). You have the coords and the handle returned would be correct.

2.) There is no reason why the first '$search = FileFindFirstFile($DESDirPath)' can't go in the while loop. You can also put the error checking in there -> if $search = -1 and @error.

I use it as the seed for 4 different loops, this is only a small part of this script with the GUI stripped from it etc.

Ok. What you have should be ok.

3.) Please post the output of both windows within a code box. - The top one is the main window the second one is the message window the final one is the actual text message control I am trying to access on the message window.

>>>> Window <<<<
Title:  AxCent
Class:  Afx:00400000:8:00010003:00000000:067C070D
Position:   -1, 0
Size:   1155, 781
Style:  0x1CCF8000
ExStyle:    0x00000110
Handle: 0x0000000000280B14

For what you want, you should not need the window handle however it can be useful when using control functions.

>>>> Window <<<<
Title:  AxCent
Class:  #32770
Position:   597, 401
Size:   486, 219
Style:  0x94C801C5
ExStyle:    0x00010101
Handle: 0x00000000004A09CE

>>>> Control <<<<
Class:
Instance:
ClassnameNN:
Name:
Advanced (Class):
ID:
Text:
Position:
Size:
ControlClick Coords:
Style:
ExStyle:
Handle:

>>>> Mouse <<<<
Position:   196, 14
Cursor ID:  0
Color:  0xBABABA

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]


>>>> Hidden Text <<<<

Every control must have a handle. Controls, like windows, have to be registered within windows because of lots of tech crap i won't go into.

This is a window as there is no control info.

>>>> Window <<<<
Title:  AxCent
Class:  #32770
Position:   333, 281
Size:   486, 219
Style:  0x94C801C5
ExStyle:    0x00010101
Handle: 0x000000000035059E

>>>> Control <<<<
Class:  Static
Instance:   2
ClassnameNN:    Static2
Name:
Advanced (Class):   [CLASS:Static; INSTANCE:2]
ID: 65535
Text:   The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]
Position:   65, 26
Size:   378, 92
ControlClick Coords:    90, 33
Style:  0x50022080
ExStyle:    0x00000004
Handle: 0x0000000000640AA0

>>>> Mouse <<<<
Position:   158, 84
Cursor ID:  0
Color:  0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[Unexpected [Access violation [r] at 41624f43] error happened.
The application may become unstable.
It is recommended to save your documents and restart the application.]


>>>> Hidden Text <<<<

As this is clearly a control within a window you will have to handle this differently. This has the same text, where is the other?

How is it you can firstly have a window then secondly a control output of the same thing? What is going on? It should be one of the other not both.

You may want to double check the output.

4.) After you have the handle to the window the only information of importance is the Control info. >>>> Visible Text <<<< is not important. You might be able to use WinGetHandle("[ACTIVE]") after your call to WinWaitActive. This might solve point 1.

I tried this and got the text from the main window ie "For Help, press F1" see jpg, bottom left corner of main window. I did notice that the message window doesn't seem to have an 'INSTANCE' number.

5.) I had errors compiling as $version was not declared. I recommend putting ' Use Opt("MustDeclareVars", 1) ' at the top of your script and trying to build. - Sorry, it had compiled and run OK for me. What does the option do?

Thanks again - John

Opt("MustDeclareVars", 1) - Variables must be pre-declared. "#AutoIt3Wrapper_Au3Check_Parameters= -d" has the same effect.

Auto does not require vars to be declared but it is worth the effort to esp when you have such a large script.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

I think this is what you were looking for. The message that it misses...

>>>> Window <<<<
Title:  AxCent
Class:  #32770
Position:   230, 371
Size:   479, 204
Style:  0x94C801C5
ExStyle:    0x00010101
Handle: 0x00000000005D0BCA

>>>> Control <<<<
Class:  Static
Instance:   2
ClassnameNN:    Static2
Name:   
Advanced (Class):   [CLASS:Static; INSTANCE:2]
ID: 65535
Text:   The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[MFC memory error
Out of memory.]
Position:   65, 26
Size:   371, 77
ControlClick Coords:    110, 30
Style:  0x50022080
ExStyle:    0x00000004
Handle: 0x00000000008C0C22

>>>> Mouse <<<<
Position:   178, 81
Cursor ID:  0
Color:  0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<
OK
The CFD data or other embedded data could not be read from the file.
Most likely this file was created by a newer version of AxCent.
The design that was read might not be usable.
[MFC memory error
Out of memory.]


>>>> Hidden Text <<<<

Thanks

John

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

So it would appear that they are the same msgbox since the IDs, class and instance are the same. This does not make things easy.

Something should work from there, if not post the outputs to the _ArrayDisplay() calls

Opt("WinTextMatchMode", 1) ; you may want to try this set to 2 as well. This is the default
Opt("WinTitleMatchMode", 2) ; help file explains this, look up opt or AutoItSetOption
AutoItSetOption("MustDeclareVars", 1)
AutoItSetOption("MouseCoordMode", 1)

#include <WinAPI.au3>
#include <Array.au3>
#include <WindowsConstants.au3>


Func whichMsgBox()
    Local $appHandle = ""
    Local $controlHandle = ""

    ; get the window handle

    If $appHandle = "" Then
        $appHandle = WinGetHandle("[ACTIVE")
    ElseIf $appHandle = "" Then
        $appHandle = WinGetHandle("classname=Afx:00400000:8:00010003:00000000:067C070D", "")
    ElseIf $appHandle = "" Then
        MouseMove(356, 14, 0) ; releates to the mouse output in your post.
        Local $h_wfp = DllCall("user32.dll", "hwnd", "WindowFromPoint", "long", MouseGetPos(0), "long", MouseGetPos(1))
        $appHandle = _WinAPI_GetAncestor($appHandle, $GA_ROOT)
    ElseIf $appHandle = "" Then
        Local $aWinList = WinList("AxCent", "")
        If $aWinList[0][0] > 0 Then ; it found something
            _ArrayDisplay($aWinList) ; see how may there are. If this does not work remove the "AxCent" param from WinList
            $appHandle = $aWinList[1][1] ; need to something like this to get the window handle.
        EndIf
    ElseIf $appHandle = "" Then
        ConsoleWrite("Error: could not get the window handle" & @CR & @extended)
        Exit
    EndIf

    ; get the control handle

    If $controlHandle = "" Then
        $controlHandle = ControlGetHandle($appHandle, "", "[ID:65535]")
    ElseIf $controlHandle = "" Then
        $controlHandle = ControlGetHandle($appHandle, "", "[CLASS:Static; INSTANCE:2]")
    ElseIf $controlHandle = "" Then
        $controlHandle = ControlGetHandle($appHandle, "", "[X:65 Y:26]")
    ElseIf $controlHandle = "" Then
        Local $nInstance, $sLastClass, $sComposite
        Local $sList = WinGetClassList($appHandle) ; list of every class in the Window
        Local $aList = StringSplit(StringTrimRight($sList, 1), @LF, 2)
        _ArraySort($aList) ; improves speed
        _ArrayDisplay($aList) ; static class should be in there. If its not the $appHandle may not correct
        ConsoleWrite("Error: could not get the control handle" & @CR & @extended)
        Exit
    EndIf

    ; when you get the control you can get the text from it.

    Local $string = ControlGetText($controlHandle, "", "")
    ; If you have issues use ControlGetHandle to test your params.
    If StringInStr($string, 'Access Violation') <> 0 Then
        Return 1 ; first message box is displayed.
    ElseIf StringInStr($string, 'Out of Memory') <> 0 Then
        Return 2 ; second message box is displayed
    Else
        SetError(1, 0, 0)
        Return 0 ; something went wrong.
    EndIf

EndFunc   ;==>whichMsgBox
Edited by bo8ster

Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Thanks for the help bo8ster, I have got it working as I expect it to, most of the time, although it does go down the catch all 'else' path a few to many times for my liking. It has identified all my bad files so far, which is what I want but sometimes a good file ends up going through the 'else' loop... that bit doesn't make sense unless the mouse position is affecting it. Perhaps I should disable the mouse and keyboard while it runs. This is just a snippet again since I have relinked it to the GUI code so its big! As you can see I went for reverse logic in that it should only go through the if...then...else if...else loop if it is not the main window. I also close and open the app each time I load and unload a file, makes for more consistent behaviour

While 1
        $selfile = FileFindNextFile($search) 
        If @error Then ExitLoop
            
      ; Run AxCent 1
        Send("#r")
        WinWaitActive("Run")
        Send($EXE1DirPath)
        Send("{ENTER}")
        
        ; Wait for AxCent to become active
        WinWaitActive("AxCent")
            
        ; Open first DES file
        Send("!F, O")
        WinWaitActive("Open")
        Send($DESDirPathOrig)
        Send("{ENTER}")
        Send("{DEL}")
        WinWaitActive ("Open")
        Send($selfile, 1)
        Send("{ENTER}")
            
        ;Wait for AxCent window to become active
        WinWaitActive("AxCent")
        If Not WinActive("AxCent", $selfile) then
                
        If WinActive("AxCent","The CFD") then   
            Send("{ENTER}")
            ;MsgBox(0, "File Failure", $selfile)
            ;MsgBox(0, "AxCent Version", $version1)
                    ;Exit
        ElseIf WinActive("AxCent","A suitable document") then
            Send("{ENTER}")
            MsgBox(0, "File Failure", $selfile)
            MsgBox(0, "AxCent Version", $version1 & " reading files from the repository")
            Exit
        Else
            Send("{Enter}") 
            ;MsgBox(0, "Wrong Path", "This file goes down a bad path")
        EndIf
        EndIf
           ;Save the file to Axcent version numbered directory 
        WinActivate("AxCent")
        Send("!F, A")
        WinWaitActive("Save As")
        Send($Version1Path & "\" & $selfile)
        Send("{ENTER}")
        Send("!F, C")
       ;Close Axcent
        WinWaitActive ("AxCent")
        Send("!F, X")   

    Wend

I will take a look at your snippet too and see if there is something that will make my procedure more reliable. And I thought this was going to be the easy bit... the worst is yet to come!

Thanks again for the input.

John

Edited by JVPK

Share this post


Link to post
Share on other sites

No probs.

The code I have is a number of different ways AutoIt can get Window and Control handles, some more complicated than others.

Your code looks good, you will have to do some debugging to file out why it hits the else when it should not. If the program is taking a long time to load look at the "WinWaitDelay" option.

You can add "#AutoIt3Wrapper_run_debug_mode=Y" at the top of your script of add scaffolding (print values using consolewrite or logging them to a file). You can add sleep functions to slow the execution of your script to see what is going on and when. It depends on how accurate you script must be.


Post your code because code says more then your words can. SciTe Debug mode - it's magic: #AutoIt3Wrapper_run_debug_mode=Y. Use Opt("MustDeclareVars", 1)[topic="84960"]Brett F's Learning To Script with AutoIt V3[/topic][topic="21048"]Valuater's AutoIt 1-2-3, Class... is now in Session[/topic]Contribution: [topic="87994"]Get SVN Rev Number[/topic], [topic="93527"]Control Handle under mouse[/topic], [topic="91966"]A Presentation using AutoIt[/topic], [topic="112756"]Log ConsoleWrite output in Scite[/topic]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0