alexf Posted March 22, 2009 Share Posted March 22, 2009 (edited) Hi everyone, I've searched the forum for a solution to this problem, and read several posts that seem related, but none of the suggestions seem to help. I'm writing a script for ImageJ (Java program, running under WinXP) and I can't read the check/uncheck flag for a checkbox and I also can't check it using ControlCommand. I used ControlGetFocus to verify the ID on the checkbox I want to edit, and it returns Button2. According to the Window Info tool, this is the info for the button: ClassnameNN: Button2 Advanced(class): [CLASS:Button; Instance:2] ID: 2 Window title: Set Measurements Here's my code: WinActivate("Set Measurements") WinWaitActive("Set Measurements") ControlFocus("Set Measurements", "", "Button2") If(ControlCommand( "Set Measurements", "", "[CLASS:Button; INSTANCE:2]", "IsChecked", "") == 1) Then MsgBox(0, "", "one is checked") ElseIf(ControlCommand( "Set Measurements", "", "[CLASS:Button; INSTANCE:2]", "IsChecked", "") == 0) Then MsgBox(0, "", "one is NOT checked") Else MsgBox(0,"",ControlCommand( "Set Measurements", "", "Button2", "IsChecked", "")) EndIf I've also tried ControlCommand with the following arguments: ControlCommand( "Set Measurements", "", "Button2", "IsChecked", "") ControlCommand( "Set Measurements", "", 2, "IsChecked", "") Edited March 23, 2009 by alexf Link to comment Share on other sites More sharing options...
alexf Posted March 23, 2009 Author Share Posted March 23, 2009 I think I understand the problem better now; the control is coming up as a "Button" even though it's a checkbox. Is there a way to force AutoIT to treat the control as a checkbox even though it shows up as a button? Link to comment Share on other sites More sharing options...
alexf Posted March 23, 2009 Author Share Posted March 23, 2009 Hi, I noticed a post referring to a library for interfacing with .NET app controls. Is something similiar necessary for interacting with a Java app? Here are the things I want to do: -Read state of checkbox -Check/uncheck checkbox -Count number of items in listbox -Loop through listbox These controls generally don't seem to behave: Checkbox always returns 0 for IsChecked (using ControlCommand) and ControlListView returns 0 for the number of elements when it's definitely not zero. The program I am writing the script for is ImageJ (written in Java), running on WinXP. Am I missing something basic? Is there a sticky or readme that explains these problems? Thanks, Alex Link to comment Share on other sites More sharing options...
alexf Posted March 23, 2009 Author Share Posted March 23, 2009 I still haven't made any progress... anyone have some ideas? Thanks, Alex Link to comment Share on other sites More sharing options...
Authenticity Posted March 23, 2009 Share Posted March 23, 2009 This control has BS_OWNERDRAW and thus use some internal WM_USER+# to determine if to set or unset the control. You may be able to get successful state of the control using "IsVisilbe" or "IsEnabled" but you can't use BM_GETCHECK or BM_SETCHECK to get or set the check state. Use Spy++ to see what messages it sends to determine if it's set or not. Link to comment Share on other sites More sharing options...
alexf Posted March 23, 2009 Author Share Posted March 23, 2009 Thanks a lot! I'm going to try the alternative Winspector, I didn't know that tools like this even existed. Alex Link to comment Share on other sites More sharing options...
rover Posted March 23, 2009 Share Posted March 23, 2009 Hi everyone, I've searched the forum for a solution to this problem, and read several posts that seem related, but none of the suggestions seem to help. I'm writing a script for ImageJ (Java program, running under WinXP) and I can't read the check/uncheck flag for a checkbox and I also can't check it using ControlCommand.Hi alexf only ControlSend works here, but its better than having to use MouseClick or Send try this example the coordinates I used are approximate, check them yourself a users selected visual styles (theme) control colours apply when using pixel functions. I think I understand the problem better now; the control is coming up as a "Button" even though it's a checkbox. Is there a way to force AutoIT to treat the control as a checkbox even though it shows up as a button?normal buttons, checkboxes, radio buttons and group controls are all 'Button' class expandcollapse popupOpt("PixelCoordMode", 2) ;2=client ;run Imagej and open Set Measurements dialog first Global $Title = "[TITLE:Set Measurements; CLASS:SunAwtDialog]" Global $Class = "[CLASS:Button; INSTANCE:2]" If Not WinExists($Title) Then Exit $winhandle = WinGetHandle($Title) ConsoleWrite('-$winhandle = ' & $winhandle & @CRLF) If Not IsHWnd($winhandle) Then Exit WinActivate($winhandle) WinWaitActive($winhandle, "", 5) $ctrlhandle = ControlGetHandle($winhandle, "", $Class) ConsoleWrite('-$ctrlhandle = ' & $ctrlhandle & @CRLF & @CRLF) If Not IsHWnd($ctrlhandle) Then Exit WinActivate($winhandle) $text = ControlGetText($winhandle, "", $ctrlhandle) $aPos = ControlGetPos($winhandle, "", $ctrlhandle) _IsChecked($winhandle, $aPos, $text) Sleep(2000) ControlFocus($winhandle, "", $ctrlhandle) ControlSend($winhandle, "", $ctrlhandle, "{SPACE}") _IsChecked($winhandle, $aPos, $text) Sleep(2000) ControlFocus($winhandle, "", $ctrlhandle) ControlSend($winhandle, "", $ctrlhandle, "{SPACE}") _IsChecked($winhandle, $aPos, $text) ;uncomment to test on all checkkboxes ;~ For $i = 1 To 22 ;~ $ctrlhandle = ControlGetHandle($winhandle, "", "[CLASS:Button; INSTANCE:" & $i & "]") ;~ $text = ControlGetText($winhandle, "", $ctrlhandle) ;~ $aPos = ControlGetPos($winhandle, "", $ctrlhandle) ;~ If _IsChecked($winhandle, $aPos, $text) Then ContinueLoop ;~ ControlFocus($winhandle, "", $ctrlhandle) ;~ ControlSend($winhandle, "", $ctrlhandle, "{SPACE}") ;~ Sleep(250) ;~ Next Func _IsChecked($hWnd, ByRef $aControlPos, $sText) Local $checksum = PixelChecksum($aControlPos[0], $aControlPos[1] + 6, $aControlPos[0] + 10, $aControlPos[1] + 18) Local $colour = PixelGetColor($aControlPos[0] + 6, $aControlPos[1] + 12, $hWnd) ConsoleWrite('-$colour = ' & $colour & @CRLF) ConsoleWrite('-$checksum = ' & $checksum & @CRLF& @CRLF) If $colour = 0 Then ConsoleWrite("+" & $sText & " IS Checked" & @CRLF) Return 1 Else ConsoleWrite("!" & $sText & " NOT Checked" & @CRLF) Return 0 EndIf EndFunc I see fascists... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now