Jump to content

Stubborn controls- or am I just out of practice?


Recommended Posts

I'm using AutoIt 3.3.6.0 on XP, SP3.

I'll admit- it's been a few years since I've used autoit, so I may have forgotten some basics.

I've used the Window Info tool to get the ID, text, and class names from some controls in the gui I'm trying to automate.

The program I'm trying to automate has 16 boxes (small windows) in it, which display text status of tests that are running.

When I click any of the 16 windows with the mouse, the frame of that small window gets highlighted, and buttons on the toolbar become enabled.

These are two visual clues that let me know that a small window has been selected, and I should see the same results when my autoit script

does the same.

Here is my script.

Global $hnd

Func _Main()
    Dim $hnd
    Dim $x

    $hnd = WinActivate("MyProgram")
    If $hnd = 0 Then
        MsgBox(0, "ACTIVATE MyProgram WINDOW", "Could not find MyProgram Window")
    Else
        ;$x = ControlClick("MyProgram", "", "[CLASS:Static;INSTANCE:10]")
        ;$x = ControlFocus("MyProgram", "", 1226)
        ;$x = ControlClick("MyProgram", "", 1017) ;

        $x = ControlClick("MyProgram", "", "[ID:1017]")
        If $x = 0 Then
            MsgBox(0, "CONTROL CLICK", "Could not find Control")
        EndIf
EndFunc

This is what I know:

* The target gui was compiled with Visual C/C++ - I think 6.x or at least a PRE .NET version (yay)! I used a hex editor to scan through the executable, and saw the typical Microsoft messages.

* My script does find the main window of the target gui and makes it active.

* My script appears to be finding the control I'm trying to automate, because the "If $x = 0 Then" does not fail.

However - none of the Boxes/controls I'm selecting using ControlClick() get highlighted, nor do the buttons on the toolbar get enabled,

yet, I never see this MsgBox(0, "CONTROL CLICK", "Could not find Control".

Any ideas what I'm doing wrong?

Link to comment
Share on other sites

A few things...

1. Nothing calls Main(), so nothing happens.

2. First If/Else/EndIf is missing EndIf.

3. Once you have the handle of a window, use that from then on (much more reliable).

Main()

Func _Main()
    Local $hnd

    $hnd = WinActivate("MyProgram")
    If IsHWnd($hnd) Then
        If ControlClick($hnd, "", "[ID:1017]") Then
            MsgBox(64, "ControlClick()", "Succeeded.")
        Else
            MsgBox(16, "ControlClick()", "Could not find Control.")
        EndIf
    Else
        MsgBox(16, "WinActivate()", "Could not find MyProgram Window")
    EndIf
EndFunc

:(

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

>>1. Nothing calls Main(), so nothing happens.

Wrong. I can see the target gui my app get activated/focused, when I execute my auto it script. The call to main is being executed.

I just did a sloppy copy & paste into the forum message.

>>2. First If/Else/EndIf is missing EndIf.

Nope. Again, bad copy and paste. Besides, if there were a syntax problem, the script wouldn't compile. ;-)

>>3. Once you have the handle of a window, use that from then on (much more reliable).

Thanks for the tip on the hndle

Edited by cappy2112
Link to comment
Share on other sites

I think PsaltyDS is correct on both counts you call as wrong.

Unfortunately no-one has access to your mind, so all there is to go on is the code you post.

Also I would get you PC looked at if copy and paste is not working, its quite a basic computer operation.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

I think PsaltyDS is correct on both counts you call as wrong.

Unfortunately no-one has access to your mind, so all there is to go on is the code you post.

Also I would get you PC looked at if copy and paste is not working, its quite a basic computer operation.

Copy & past works, I just didn't highlight everything correctly. It happens.

If you think the script doesn't run, then how do you explain the script activating the target application? This proves the call to main executed, even though it wasn't visible

due to my sloppy copy & paste.

I've intentionally minimized the target application, so I would know that it was being activated by my script.

_Main()

Global $hnd

Func _Main()

    Dim $hndBasher
    Dim $x

    $hnd= WinActivate("MyProgram")
    If $hnd= 0 Then
        MsgBox(0, "ACTIVATE TARGET APPLICATION WINDOW", "Could not find Target App Window")
    Else
        $x = ControlClick("MyProgram", "", "[ID:1017]")
        If $x = 0 Then
            MsgBox(0, "CONTROL CLICK", "Could not find Control")
    Else
            MsgBox(0, "CONTROL CLICK", "Control was found")
        EndIf
    EndIf

EndFunc ;==>_Main

The code above is complete, no sloppy copy & paste.

The code above runs the same as what I pasted yesterday, however I've added this as confirmation that the script "thinks" the control was found

Else
            MsgBox(0, "CONTROL CLICK", "Control was found")
        EndIf

When I run the code above, I do see the message box display "Control was found".

However, the target app doesn't respond the same as when I click the control with the mouse.

When I click the target control with the mouse, it is highlighted.

When the script above effectively clicks the target control, the control is not highlighted.

I don't understand why.

The forum editor has a problem- there is an Else which isn't appearing in the correct place, making the code look wierd.

However, I've edited it 3 times, but the forum software isn't taking the changes- even though I've saved them.

I've attached a screenshot as proof.

post-6875-12708371454633_thumb.jpg

Edited by cappy2112
Link to comment
Share on other sites

The code above is complete, no sloppy copy & paste.

Would have been nice to start from there to begin with... :(

When I run the code above, I do see the message box display "Control was found".

However, the target app doesn't respond the same as when I click the control with the mouse.

When I click the target control with the mouse, it is highlighted.

When the script above effectively clicks the target control, the control is not highlighted.

I don't understand why.

What is the nature of the app? Are you sure the ID is for the specific control, and not a higher container (i.e. a flash object that contains controls, or java app)?

:)

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law
Link to comment
Share on other sites

When you say "effectively clicks", do you mean the click is succesful, in that it carries out its function but just dosent get focus ?

Perhaps the app needs the mouse over it to register focus, have you tried GUICtrlSetState([iD:1017], $GUI_FOCUS)

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Would have been nice to start from there to begin with... :(

What is the nature of the app? Are you sure the ID is for the specific control, and not a higher container (i.e. a flash object that contains controls, or java app)?

:)

>>Would have been nice to start from there to begin with

Agreed. I will be more careful when pasting code in the future:oops:

The nature of the app is:

It is a control program for a piece of test equipment for an embedded storage device. Each "window" in the program talks to one tester over ethernet.

The purpose of the software is to start and stop test programs, as well as download the test program to the tester.

No flash, no java, no internet / web protocols.

We dont have the source for the app, which is why I'm trying to automate it.

Link to comment
Share on other sites

When you say "effectively clicks", do you mean the click is succesful, in that it carries out its function but just dosent get focus ?

Perhaps the app needs the mouse over it to register focus, have you tried GUICtrlSetState([iD:1017], $GUI_FOCUS)

The click is not successful, because the control never gets highlighted, and the call to ControlClick() returns an error code.

I will try to send the GUI_FOCUS first, then try clicking.

I posted another message about this- I used Spy++ and I'm actually able to get the control ID AND the handle of the control with it.

AutoIt WIndow Info can't get the control ID, however when I try the control ID in the code I originally posted, it still doesn't work.

THanks

Link to comment
Share on other sites

When you say "effectively clicks", do you mean the click is succesful, in that it carries out its function but just dosent get focus ?

Perhaps the app needs the mouse over it to register focus, have you tried GUICtrlSetState([iD:1017], $GUI_FOCUS)

Hmm. According to the documentation, GUICtrlSetState() works with a Control ID returned from GuiCtrlCreate function.

The GUI I'm trying to automate is not made with auto it. It was created by an external company, using Visual C/C++.

Actually- I get a a compile error on GUICtrlSetState("[iD:1017]", $GUI_FOCUS)

"$GUI_FOCUS possibly used before declaration."

GUICtrlSetState Changes the state of a control.

GUICtrlSetState ( controlID, state )

Parameters

controlID The control identifier (controlID) as returned by a GUICtrlCreate... function.

Edited by cappy2112
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...