Sign in to follow this  
Followers 0
jcradio

ClassnameNN Occasionally changes

6 posts in this topic

Has anyone else run into the weird occurrence of a control's ClassnameNN changing? I have written a script that mines data from several screens of a third party app and builds it into a delimited text file. Many of the controls are Static controls with which I retrieve data using the ControlGetText function. I have noticed now that on occasion, the controls may change between instances of the app, or may change during the execution of the app, but not until it is several records in. For example, on the first 17 records it may accurately retrieve data from "Static38", but suddenly that same control is now referenced as "Static39" and the data is not scraped. I thought that it was just the one control, but now I am finding this to be the case in almost all of the controls, which is making it near impossible to achieve what I am trying to do. Ideally, I would prefer to have a function that would return the ClassnameNN based on mouse position thus getting the name during each pass of the loop, ensuring that the correct name is being used.

Any Ideas?

Share this post


Link to post
Share on other sites



Search the forum for "WindowFromPoint". It's a function in User32.dll, and there are several AutoIt functions posted to use it.

:)


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

Share this post


Link to post
Share on other sites

Search the forum for "WindowFromPoint". It's a function in User32.dll, and there are several AutoIt functions posted to use it.

:)

Thanks! I have been looking into it. I will research how to implement it. The issue with most of the 'control' functions is that they require a control ID. This does not work for the "static" controls in the app, because they do not get assigned an ID. I would love a function that would return the classnameNN of the control directly beneath the x,y coord like this ControlGetText(x,y).

Share this post


Link to post
Share on other sites

windowfrompoint for the hwnd... pass it to http://www.autoitscript.com/forum/index.php?showtopic=32781&view=findpost&p=236417

Lar.


f_mrcleansmalm_77ce002.jpgAutoIt has helped make me wealthy

Share this post


Link to post
Share on other sites

windowfrompoint for the hwnd... pass it to #236417

Lar.

Again, more good info. I was looking at that, too. However, doesn't that return everything? The issue that I run into is say I have 32 static controls on a screen, but only need information from 16 of them. Well, I know the X,Y coords of each of the controls, but I do not know what their ClassnameNN will be. Sometimes the ClassnameNN of the control changes. When it happens after 17 loops of the code it is frustrating. I am still relatively new to AutoIT, but what I have managed to do so far is amazing. I am certain that I will eventually come up with a way to do it, I just thought I would see if anyone else has. I am 8 projects deep at work and don't know when I will have time to develop what I need.

Thanks!

Share this post


Link to post
Share on other sites

Thanks! I have been looking into it. I will research how to implement it. The issue with most of the 'control' functions is that they require a control ID. This does not work for the "static" controls in the app, because they do not get assigned an ID. I would love a function that would return the classnameNN of the control directly beneath the x,y coord like this ControlGetText(x,y).

Read the methods for special definition under "Controls" in the help file:

A special description can be used as the controlID parameter used in most of the Control...() functions . This description can be used to identify a control by the following properties:

ID - The internal control ID. The Control ID is the internal numeric identifier that windows gives to each control. It is generally the best method of identifying controls. In addition to the AutoIt Window Info Tool, other applications such as screenreaders for the blind and Microsoft tools/APIs may allow you to get this Control ID

TEXT - The text on a control, for example "&Next" on a button

CLASS - The internal control classname such as "Edit" or "Button"

CLASSNN - The ClassnameNN value as used in previous versions of AutoIt, such as "Edit1"

NAME - The internal .NET Framework WinForms name (if available)

REGEXPCLASS - Control classname using a regular expression

X \ Y \ W \ H - The position and size of a control.

INSTANCE - The 1-based instance when all given properties match.

You can locate it by the position (X/Y) of the left/top corner:
#include <GuiConstantsEx.au3>
#include <WinAPI.au3>

Opt("PixelCoordMode", 2) ; 2 = relative coords to the client area of the defined window

Global $hGUI, $ctrlButton, $hButton, $ctrlTest, $ctrlTest

$hGUI = GUICreate("Test", 200, 200)
$ctrlButton = GUICtrlCreateButton("TEST", 50, 50, 100, 100)
ConsoleWrite("Debug: $ctrlButton = " & $ctrlButton & @LF)
$hButton = ControlGetHandle($hGUI, "", $ctrlButton)
ConsoleWrite("Debug: $hButton = " & $hButton & @LF)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $ctrlButton
            $hTest = ControlGetHandle($hGUI, "", "[X:50; Y:50]") ; Get handle by pos
            ConsoleWrite("Debug: $hTest = " & $hTest & @LF)
            $ctrlTest = _WinAPI_GetDlgCtrlID($hTest) ; Get ControlID from handle
            ConsoleWrite("Debug: $ctrlTest = " & $ctrlTest & @LF)
    EndSwitch
WEnd

If you get the handle from a "WindowFromPoint" call then you just use _WinAPI_GetDlgCtrlID() to get the ControlID.

:)


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

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