Jump to content

Can't ControlGetText by position


Recommended Posts

I'm attempting to use ControlGetText by using X & Y coordinates.

I can access the control by class & instance, but the program gives it a new instance every time the program runs.

So I can get the correct coordinates both by AutoIT Window Info and the following script this script

$pos=ControlGetPos("[CLASS:RApplicationClass]","","[CLASS:TRTIMaskEdit; INSTANCE:2]")

MsgBox(0, "Window Stats:", "POS: " & $pos[0] & "," & $pos[1] & " SIZE: " & $pos[2] & "," & $pos[3] )

but when I try to access by those coordinates

$tst=ControlGetText("[CLASS:RApplicationClass]","","[CLASS:TRTIMaskEdit; X:95; Y:117]")

MsgBox(0, @error, $tst)

It basically returns an error (1) and no data

Below are the results of AutoIt Window Info

Any ideas?

Thanks in advance

-----

>>>> Window <<<<

Title: RApplication

Class: RApplicationClass

Position: -1, -5

Size: 1288, 805

Style: 0x16CF0000

ExStyle: 0x00010100

Handle: 0x0011053C

>>>> Control <<<<

Class: TRTIMaskEdit

Instance: 2

ClassnameNN: TRTIMaskEdit2

Name:

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

ID: 5244638

Text:

Position: 95, 117

Size: 162, 21

ControlClick Coords: 137, 12

Style: 0x540100C6

ExStyle: 0x00000200

Handle: 0x005006DE

>>>> Mouse <<<<

Position: 232, 129

Cursor ID: 0

Color: 0xFFFFFF

>>>> StatusBar <<<<

>>>> ToolsBar <<<<

>>>> Visible Text <<<<

Customers

FormPage

Company

Cust ID

10

E-Mail

Cust.Notes

Inactive

Str/Sta

MAIN

Miscellaneous

User Defined

Info

Customer

Customer Info

>>>> Hidden Text <<<<

GridPage

Customer Lookup [100%]

WebBrowseForm

Panel1

Link to comment
Share on other sites

It's possible that control doesn't respond to the normal "get text" API used by AutoIt. Try something else, like getting its handle. For example, this works fine:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("RApplication", 352, 208)
GUICtrlCreateInput("Edit text here...", 95, 117, 162, 21)
$idButton = GUICtrlCreateButton("Test Me!", 126, 158, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            $hEdit = ControlGetHandle("[CLASS:AutoIt v3 GUI; TITLE:RApplication]", "", "[CLASS:Edit; X:95; Y:117]")
            ConsoleWrite("$hEdit = " & $hEdit & "; @error = " & @error & @LF)
            $sTxt = ControlGetText("[CLASS:AutoIt v3 GUI; TITLE:RApplication]", "", "[CLASS:Edit; X:95; Y:117]")
            ConsoleWrite("$sTxt = " & $sTxt & "; @error = " & @error & @LF)
    EndSwitch
WEnd

:D

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

It's possible that control doesn't respond to the normal "get text" API used by AutoIt. Try something else, like getting its handle. For example, this works fine:

#include <GuiConstantsEx.au3>

$hGUI = GUICreate("RApplication", 352, 208)
GUICtrlCreateInput("Edit text here...", 95, 117, 162, 21)
$idButton = GUICtrlCreateButton("Test Me!", 126, 158, 100, 30)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $idButton
            $hEdit = ControlGetHandle("[CLASS:AutoIt v3 GUI; TITLE:RApplication]", "", "[CLASS:Edit; X:95; Y:117]")
            ConsoleWrite("$hEdit = " & $hEdit & "; @error = " & @error & @LF)
            $sTxt = ControlGetText("[CLASS:AutoIt v3 GUI; TITLE:RApplication]", "", "[CLASS:Edit; X:95; Y:117]")
            ConsoleWrite("$sTxt = " & $sTxt & "; @error = " & @error & @LF)
    EndSwitch
WEnd

:D

Thanks psaltyDS.

Unfortunately, ControlGetHandle isn't able to get the handle by X&Y position either.

Link to comment
Share on other sites

You know the X/Y values are the top left corner position, window client area relative, right?

You can't specify just any pixel position inside the control. For that, try _WinAPI_WindowFromPoint().

:D

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

I tried the WinControlList.au3 script elsewhere on this forum and it was able to find the control and get to the text.

The only problem is that the script is very complicated.

I need to look through all the child windows looking for the control at position x & y

At some point I saw someone else's script that would do a similar function, but now i can't find it.

Can anyone point me to this script?

Thanks

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...