Sign in to follow this  
Followers 0
someone

ControlGetText

11 posts in this topic

#1 ·  Posted (edited)

Hey everyone,

I'm trying to make a script to read text from a program that I use at work and copy it into something else(in case anyone has a similiar program its made by Peregrine). The problem is that the ControlID and classname changes randomly, and for other controls I can't seem to get any text at all. I looked into LxPs _ControlGetHandleByPos but the function doesn't seem to return anything(see below..I dont know if its the same problem or I am using _ControlGetHandleByPos wrong). See the screenshots below...

In controls.bmp you can see a list of controls that you can click on while in the program. I need to be able to click on them since I need information on at least a few of the tabs. The problem is that all the tabs have the same controlID and classname, and nothing seems to happen at all if I use ControlClick with that ID. Here is the autoit window info

Press CTRL-ALT-F to freeze the display.

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: xxxxx(removed)xxxxx

Class: SWT_Window0

Size: X: -4 Y: -4 W: 1032 H: 746

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Screen: X: 404 Y: 282

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0x3F5F7F Dec: 4153215

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 53 Y: 217 W: 824 H: 22(same for all tabs)

Control ID: 6555304(same for all tabs)

ClassNameNN: Static6(same for all tabs)

Text: Incident Management(same for all tabs)

Style: 0x5400010C(same for all tabs)

ExStyle: 0x00100000(same for all tabs)

(Control is hidden)

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

07952821

And for whatever reason using _ControlGetHandleByPos doesn't return anything... not an error the script just exits. If I use bad coordinates though I do get an error message. Heres the code for _ControlGetHandleByPos

#include <Process.au3>
Local $hControl

WinActivate("Center","")
WinWaitActive("Center","")
Sleep(2000) ; Used to make sure it wasn't a window activation problem
$hControl = _ControlGetHandleByPos("Center", "", 53, 217)

If @error Then
    MsgBox(48, "_ControlGetHandleByPos() Example", "Something went wrong!")
Else
    ControlSetText("Run", "", $hControl, "This control was found by its position.")
EndIf

Func _ControlGetHandleByPos($sTitle, $sText, $iX, $iY)
EndFunc
(I removed the body of the func since it is unmodified from LxPs and to make the post shorter)

The Scite ouput is simply this..

Running:(3.2.2.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\W016933\Desktop\_ControlGetHandleByPos_Example.au3"

+>AutoIT3.exe ended.rc:0

>Exit code: 0 Time: 5.426

Also some of the edit boxes within the program are weird.. (screenshot EditBox) The autoit window info for the box is;

Same above this line as prev window info

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 57 Y: 527 W: 922 H: 105

Control ID: 5637900

ClassNameNN: SWT_Window0125

Text:

Style: 0x56210000

ExStyle: 0x00100000

Same Below this line as prev window info

Doing a controlgettext on that ID or Classname produces nothing, and doing a _ControlGetHandleByPos on the coords(57, 527) again produce nothing, not an error just nothing.

Sorry for the huge post just wanted to make myself clear. As far as I know there are no keyboard shortcuts or anything like that that would help me get the text or click on controls I need. I've been banging my head trying to figure this out so its entirely possible I'm not making much sense at this point, so if I left anything out or I'm you need more/better information let me know.

Thanks everyone,

Andrew

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

I've tried reading up some on SWT windows... could that have something to do with why I'm having trouble?

EDIT: I changed the example code above... probably should have caught it earlier now instead of nothing I get a number like 0x00B00592 that keeps changing, and if I use that as a control nothing seems to happen.

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

I think I have officially run out of ideas.... :)

How do you ever maniuplate programs without control ID, classname, etc?


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Hmm alright I probably won't bump this again... sorry to be a pest. Anyone have any ideas??


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

1 Have a look at _CtrlGetByPos() by SmOke_N.

2. Search for ControlClassNNFromMousePos. It is a function that is done by Larry. If you look closely, you can see that the file is catching the current mouse-position. You could just set fixed values an you're done. :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Thanks VERY much for the reply. How is _CtrlGetByPos() any different then what LxP wrote? I didn't try SmOke_N's code out just yet but LxPs returns either a constantly changing number or nothing(it returns nothing on one control(the editbox.bmp) and changing numbers on other controls). Heres my code so you can see what I'm doing.

#include <Process.au3>
Local $hControl

WinActivate("title","")
WinWaitActive("title","")
$hControl = _ControlGetHandleByPos("title", "", 57, 527)
If @error Then
    MsgBox(48, "_ControlGetHandleByPos() Example", "Something went wrong!")
Else
EndIf

Func _ControlGetHandleByPos($sTitle, $sText, $iX, $iY)

    Local $hWin, $hControl
    Local $iControls, $iLoop, $iUniqueControls
    Local $sClassList, $sClass, $sClassID
    Local $aiControlPos, $avUniqueControls[1][2]

    ; Determine that the window exists
    $hWin = WinGetHandle($sTitle, $sText)
    If @error Then
        SetError(2)
        Return 0
    EndIf

    ; Determine the control classes and total number of controls
    $sClassList = WinGetClassList($hWin)
    $iControls = StringLen($sClassList) - StringLen(StringReplace($sClassList, @LF, ""))
    ReDim $avUniqueControls[$iControls][2]

    $iUniqueControls = 0
    While $sClassList
        $sClass = StringLeft($sClassList, StringInStr($sClassList, @LF) - 1)
        $sClassList = StringMid($sClassList, StringLen($sClass) + 2)
        $sClassID = ""
        For $iLoop = 0 To $iUniqueControls - 1
            If $avUniqueControls[$iLoop][0] = $sClass Then
                $avUniqueControls[$iLoop][1] += 1
                $sClassID = $sClass & $avUniqueControls[$iLoop][1]
                ExitLoop
            EndIf
        Next
        If Not($sClassID) Then
            $avUniqueControls[$iUniqueControls][0] = $sClass
            $avUniqueControls[$iUniqueControls][1] = 1
            $iUniqueControls += 1
            $sClassID = $sClass & "1"
        EndIf
        ; Determine the position of the control in question
        $hControl = ControlGetHandle($hWin, "", $sClassID)
        $aiControlPos = ControlGetPos($hWin, "", $hControl)
        If ($aiControlPos[0] = $iX And $aiControlPos[1] = $iY) Then Return $hControl
    WEnd

    ; If we reach this point then no matching control was found
    SetError(1)
    Return 0

EndFunc
$msg = ControlGetText("title", "", $hControl)
MsgBox(0,"", $msg)

That code point the function the editbox.bmp and ControlGetText returns an empty string. I'll try out _CtrlGetByPos() and see if I have any different results... what about clicking on that toolbar? got any thoughts? with any tool I've tried it always have the same ID/classname for the whole list of tabs.

PS sorry this is written fast I'm trying to get out of work.

EDIT: cleaned it up a little bit...

Edited by someone

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Make sure you use Client Coords in your AutoInfo.exe (Options >> Coord Mode >> Client) or you won't get any results.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Really... and I mean "really really"... you cannot expect help from such vague and limited information. A custom control can behave in an unlimited number of ways. The application developer could have overlapped hundreds of controls. Every one of those controls may live beneath the same pixel position (mouse position).

So, either post a link where we can install (if freely) this app, or give us entire screenshots or at least the name of the application... I don't know... just don't expect us to flail blindly along side of you...

good luck.

Lar.

@Lar I'm sorry to not give you what info you are looking for, I'd be more then happy to give you whatever I can, I guess like you gathered I'm a little lost in this. Unfortunately there is no way that I know of for you to install the app free or not, but the name of the app is Peregrine Service Center. I'll definitely get up some whole screenshots when I'm at work tomorrow.

I never try to waste anyones time asking for help. :) I'll get up the screenshots, what else would help?

@SmOke_N

Thanks I do have the coords in client mode.. should I post up a pic of where the coords are pointing or anything? Just let me know what I can do to help make more sense.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

What version of ServiceCenter are you using?

LAr.

I'll have to check tomorrow for certain but I *think* its 6.12xxx I might be wrong. Is that a well known application?

While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Thats interesting... I'll have to play around when I get access to the app tomorrow. Thanks


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

Share this post


Link to post
Share on other sites

Ok here is a pic as promised...

I put arrows next to the 2 things I can't seem to control. The first is like a toolbar, the second is a box with text in it. For the box all I need to do is read the text in it.

The program is Peregrine ServiceCenter ver 6.1.2.0 Its made by HP http://www.peregrine.com/ I looked on the website but I really don't know what I'm looking for.

Here are the autoit window infos for both the toolbar and the box...

BOX

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: title(edited for privacy)

Class: SWT_Window0

Size: X: -4 Y: -4 W: 1032 H: 746

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Client: X: 310 Y: 543

Cursor ID: 5

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0xECE9D8 Dec: 15526360

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 57 Y: 527 W: 922 H: 105

Control ID: 5376366

ClassNameNN: SWT_Window0125

Text:

Style: 0x56210000

ExStyle: 0x00100000

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

07952821

12/27/06 12:48:04

Closed

Complete Audit Trail History

monitor is blank, no image appears

12/27/06 09:10:31

P3

00:22:27

TOOLBAR

>>>>>>>>>>>> Window Details <<<<<<<<<<<<<

Title: title(edited for privacy)

Class: SWT_Window0

Size: X: -4 Y: -4 W: 1032 H: 746

>>>>>>>>>>> Mouse Details <<<<<<<<<<<

Client: X: 80 Y: 231

Cursor ID: 2

>>>>>>>>>>> Pixel Color Under Mouse <<<<<<<<<<<

RGB: Hex: 0x48489C Dec: 4737180

>>>>>>>>>>> Control Under Mouse <<<<<<<<<<<

Size: X: 53 Y: 217 W: 824 H: 22

Control ID: 12650272

ClassNameNN: Static6

Text: Incident Management

Style: 0x5400010C

ExStyle: 0x00100000

(Control is hidden)

>>>>>>>>>>> Status Bar Text <<<<<<<<<<<

>>>>>>>>>>> Visible Window Text <<<<<<<<<<<

07952821

12/27/06 12:48:04

Closed

Complete Audit Trail History

monitor is blank, no image appears

12/27/06 09:10:31

P3

00:22:27

No matter where I am on the toolbar the above stays the same.

I didn't include more screen shots because I wasn't sure what else would help. If I missed something that would help anyone understand better what I'm doing or the problem PLEASE tell me, I'll try to get you whatever you want.

@Larry... either the ability to edit macros has been taken out of my version of has been disabled through some config file as its not there. I'll keep looking into it but I have a feeling it isn't there anymore... even the smacro.exe isn't on my system.


While ProcessExists('Andrews bad day.exe')
	BlockInput(1)
	SoundPlay('Music.wav')
	SoundSetWaveVolume('Louder')
WEnd

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