Sign in to follow this  
Followers 0
naaloh

Getting the state of a Delphi app Radio Button

8 posts in this topic

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

Share this post


Link to post
Share on other sites



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?

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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.

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

Share this post


Link to post
Share on other sites

then you should try GUICtrlRead

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

then you should try GUICtrlRead

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

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

Share this post


Link to post
Share on other sites

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


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

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)

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