Jump to content

Recommended Posts

Posted

Hello, everyone.

I'm a new AutoIt user (switched recently from AutoHotkey becase it has more limitations and its syntax is very bad compared to AutoIt).

Right now I'm trying to write a script which includes automating an application unfortunately written in Delphi. Even more unfortunately in the course of automation I need to have a radio button depressed. The problem here is to find out its current state - ControlCommand "IsChecked" always returns 1, so as far as I undertand, the only way I could determine the state is by detecting its appearance (the button changes color when depressed). How can I do that with AutoIt?

Here is the piece of code for the the button from the Delphi form, just in case it might be helpful.

object connbutton: TMyToolButton
Left = 0
Top = 0
Width = 55
Height = 50
Hint = 'Connect/Disconnect to server'
Caption = 'Connect'
ImageIndex = 0
Images = ImageList2
Theme = Office2003Blue
Transparent = True
ShowHint = True
TabOrder = 7
OnClick = connbuttonClick
Layout = blGlyphTop
Style = bsCheck
end
Posted

You only mentioned your attempt using ControlCommand. Did you try the function GuiCtrlSetData?

Then if that fails, you can always bring up your app, find out how many tabs it takes to select your control, and then send it a space. Or maybe you can change the radiobutton caption from "Connect" to "&Connect" and send an alt-c?

Posted (edited)

  On 11/10/2011 at 9:14 PM, 'rodent1 said:

You only mentioned your attempt using ControlCommand. Did you try the function GuiCtrlSetData?

Have you even tried to read the description of GuiCtrlSetData? This function is for working with controls created by AutoIt scripts and has nothing to do with controls of other applications.

  On 11/10/2011 at 9:14 PM, 'rodent1 said:

Then if that fails, you can always bring up your app, find out how many tabs it takes to select your control, and then send it a space. Or maybe you can change the radiobutton caption from "Connect" to "&Connect" and send an alt-c?

Would you mind telling me what on earth it has to do with my question? I don't need tabs, spaces, alts or cs to change the state of the control, ControlClick works just fine. The problem is, because it's a radio button, I need to know if it isn't already checked before I send the click (because it it is, it'll obviously become unchecked afterwards). BTW, this button cannot be reached by pressing tabs, they don't really work in that application. Edited by naaloh
  • Moderators
Posted

rodent1,

GUICtrl* functions only work on AutoIt created controls. They need the ControlID returned from the appropriate GUICtrlCreate* function as the ID parameter. So they will be of absolutely no use with a third party app. :oops:

naaloh,

Delphi controls are notoriously hard to deal with as they seem not to be created by the standard API. In the past I have needed to use PixelGetColor to check the colour of the interior of the radio button. A bit clumsy but it has worked adequately. :D

Is the app GUI of a fixed size with the radio always in the same position within it? If so, then the problem is trivial - if not, then it becomes a bit more difficult. Let me know and we can try and get you a solution. :rip:

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted (edited)

  On 11/11/2011 at 3:29 PM, 'rodent1 said:

then you should try GUICtrlRead

And you really should try reading the description of the functions you're suggesting to use :D

  On 11/11/2011 at 3:38 PM, 'Melba23 said:

Delphi controls are notoriously hard to deal with as they seem not to be created by the standard API. In the past I have needed to use PixelGetColor to check the colour of the interior of the radio button. A bit clumsy but it has worked adequately. :oops:

Is the app GUI of a fixed size with the radio always in the same position within it? If so, then the problem is trivial - if not, then it becomes a bit more difficult. Let me know and we can try and get you a solution. :rip:

M23

I think PixelChecksum that I discovered today will be most suitable for my needs, as it can check the whole button area rather than just one pixel. As far as I can tell, the position of the button inside the window doesn't change, but even if it did, I could always retrieve the coordinates via ControlGetPos. The problem, however, is that PixelChecksum seems to include the mouse pointer in the image it calculates checksum for. Can I temporarily hide the mouse pointer with AutoIt? Edited by naaloh
  • Moderators
Posted

naaloh,

PixelCheckSum will work just as well as PixelGetColor - I very nearly mentioned it earlier. Just make sure that nothing else within the area you are using changes colour at any time. :D

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

  Reveal hidden contents

 

Posted

  On 11/11/2011 at 4:52 PM, 'Melba23 said:

Just make sure that nothing else within the area you are using changes colour at any time. :D

Like what might it be?

BTW, it turned out there were no need to worry about mouse pointer, it looks like it's ignored when the hwnd parameter is specified. Here's the sample script which displays decimal CRC of the control

AutoItSetOption ("PixelCoordMode", 0)
$hwnd = WinGetHandle ("Alt.Binz")
$ConPos = ControlGetPos($hwnd, "", "TMyToolButton13")
$CRC = PixelChecksum($ConPos[0], $ConPos[1], $ConPos[0]+$ConPos[2]-1, $ConPos[1]+$ConPos[3]-1, 1, $hwnd, 1)
MsgBox(0, "CRC", "CRC is "&$CRC)

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
  • Recently Browsing   0 members

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