Sign in to follow this  
Followers 0
HungerHlp

Check or uncheck a checkbox in a list box control

14 posts in this topic

Hi, every one, I met a problem that how to check or uncheck a checkbox in a list box control in another application written by other language.

Is this operation possible? If yes, could you tell me how to do that.

Details are like this, i want to CHECK or UNCHECK a check-box in a list-box control, but this check-box can't be recognized by "AutoIT Window Info" tool, what i can get is only List-box's ID, and text of every item in list-box, But can't get state of each check-box. For example, i want to UNCHECK first check-box in list-box by some condition, Does this possible?

May you can get known by attachment, if my description confused you.

Thanks for your help/advice, and have a nice day.

post-49782-1242711177_thumb.png

Share this post


Link to post
Share on other sites



Hi, every one, I met a problem that how to check or uncheck a checkbox in a list box control in another application written by other language.

Is this operation possible? If yes, could you tell me how to do that.

Details are like this, i want to CHECK or UNCHECK a check-box in a list-box control, but this check-box can't be recognized by "AutoIT Window Info" tool, what i can get is only List-box's ID, and text of every item in list-box, But can't get state of each check-box. For example, i want to UNCHECK first check-box in list-box by some condition, Does this possible?

May you can get known by attachment, if my description confused you.

Thanks for your help/advice, and have a nice day.

You can get the handle for the listview with ControlGetHandle. Then you can use _GUICtrlListView_SetItemChecked from GuiListView.au3. You can read the state of the checkbox with _GUICtrlListView_GetItemChecked.

This is assuming that the listview is a standard windows listview.

Welcome to the forums :)


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

You can get the handle for the listview with ControlGetHandle. Then you can use _GUICtrlListView_SetItemChecked from GuiListView.au3. You can read the state of the checkbox with _GUICtrlListView_GetItemChecked.

This is assuming that the listview is a standard windows listview.

Welcome to the forums :)

Thanks for your reply and your warm welcome.

Sorry, I've not describe my solution clearly, I've got list-box's handle by $hwd = ControlGetHandle("Select Test Cases", "", "[iD:5061]"), and I know, The control is not a standard list view, but it's a list box. (Attachment is information of that control). And I've tried as your mentioned, with this code: "ConsoleWrite("Set first as checked: " & _GUICtrlListView_SetItemChecked($hwd, 0) & @CR), From the result is false, So this solution is not doable.

Before i posted this, i tried some other ways, but all failed, problems get together in one that I can't get ID of check-box, So any further handle is impossible to do.

And I've found a topic named "checkboxes in ListBox problem", Melba23 said, "Autoit apparently cannot read multicolumn listboxes created in an external application coded in another language". So i doubt does this really have a way to solve my problem?

Hope not bother you.

Thanks

HungerHlp

post-49782-1242717117_thumb.png

Share this post


Link to post
Share on other sites

Thanks for your reply and your warm welcome.

Sorry, I've not describe my solution clearly, I've got list-box's handle by $hwd = ControlGetHandle("Select Test Cases", "", "[iD:5061]"), and I know, The control is not a standard list view, but it's a list box. (Attachment is information of that control). And I've tried as your mentioned, with this code: "ConsoleWrite("Set first as checked: " & _GUICtrlListView_SetItemChecked($hwd, 0) & @CR), From the result is false, So this solution is not doable.

Before i posted this, i tried some other ways, but all failed, problems get together in one that I can't get ID of check-box, So any further handle is impossible to do.

And I've found a topic named "checkboxes in ListBox problem", Melba23 said, "Autoit apparently cannot read multicolumn listboxes created in an external application coded in another language". So i doubt does this really have a way to solve my problem?

Hope not bother you.

Thanks

HungerHlp

ControlClick might help? Just a try :)

Share this post


Link to post
Share on other sites

ControlClick might help? Just a try :party:

Yeah, As your mentioned, ControlClick ( "title", "text", controlID [, button [, clicks [, x [, y ]]]] ), This is a prototype, Call this function needs controlID, But till now, I can't get ID of check-box, because Its unrecognizable by AutoIT v3 Window Info, And I have tried to use this function as: ControlClick("Select Test Case", "", "", "left", $pos[0], $pos[1]), This does function, but If I have to check/uncheck it with specified condition, and I dont know current check state, So how can I operate it?

Anyway, thank you :)

HungerHlp

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Yeah, As your mentioned, ControlClick ( "title", "text", controlID [, button [, clicks [, x [, y ]]]] ), This is a prototype, Call this function needs controlID, But till now, I can't get ID of check-box, because Its unrecognizable by AutoIT v3 Window Info, And I have tried to use this function as: ControlClick("Select Test Case", "", "", "left", $pos[0], $pos[1]), This does function, but If I have to check/uncheck it with specified condition, and I dont know current check state, So how can I operate it?

Anyway, thank you :)

HungerHlp

Hmmm that's a little complicated one there. If the check box are at a fixed point then you can do a GetPixel and manipulate. For example:

In the screenshot you can see the checkbox with green check.... Its color is 0x21A121. So i use pixelgetcolor for check1 with exact coordinates and then a IF condition will do the job.post-29292-1242725931_thumb.jpg

Edited by Mahesh1

Share this post


Link to post
Share on other sites

Hmmm that's a little complicated one there. If the check box are at a fixed point then you can do a GetPixel and manipulate. For example:

In the screenshot you can see the checkbox with green check.... Its color is 0x21A121. So i use pixelgetcolor for check1 with exact coordinates and then a IF condition will do the job.post-29292-1242725931_thumb.jpg

Wow, may be it's a way to solve my problem, But I'm a newer for AutoIT, Could you give an example or some codes for doing that.

Thanks. :)

Share this post


Link to post
Share on other sites

Wow, may be it's a way to solve my problem, But I'm a newer for AutoIT, Could you give an example or some codes for doing that.

Thanks. :)

Attached a sample. :party:

test.au3

Share this post


Link to post
Share on other sites

Attached a sample. :)

Working now?

Share this post


Link to post
Share on other sites

Working now?

Sorry for my late response, I really really thank your for your passionate help.

Yeah, I've run that code and found it really a way to get check-box's check state on some cases, But, Now, My problem is that I can't get check-box's handle, that check-box(es) exist(s) in a list-box control, one more thing, I can't get check-box's ID by "AutoIT V3 Window Info" tool, So It's also a hard cake to eat!

Give your some of my code:

$hwd = ControlGetHandle("Select Test Cases", "", "[iD:5061]") ; Get handle of List-box

$count = _GUICtrlListBox_GetCount($hwd) ; Get size of list-box

For $index = 0 To $count - 1

_GUICtrlListBox_SetCurSel($hwd, $index)

;MsgBox(0, "state", GUICtrlRead($hwd))

$data = _GUICtrlListBox_GetText($hwd, $index) ; Get check-box's text

$handle = WinGetHandle($data) ;Test it can get check-box's handle?

ConsoleWrite("handle is " & $handle &@CR)

Next

BUT, unfortunately, The output is : "handle is ", it seems that It's also not working here, Of course, It should under condition that my usage of that function is right?

Thanks again, And Sorry for occupying your some much time.

Share this post


Link to post
Share on other sites

Sorry for my late response, I really really thank your for your passionate help.

Yeah, I've run that code and found it really a way to get check-box's check state on some cases, But, Now, My problem is that I can't get check-box's handle, that check-box(es) exist(s) in a list-box control, one more thing, I can't get check-box's ID by "AutoIT V3 Window Info" tool, So It's also a hard cake to eat!

Give your some of my code:

$hwd = ControlGetHandle("Select Test Cases", "", "[iD:5061]") ; Get handle of List-box

$count = _GUICtrlListBox_GetCount($hwd) ; Get size of list-box

For $index = 0 To $count - 1

_GUICtrlListBox_SetCurSel($hwd, $index)

;MsgBox(0, "state", GUICtrlRead($hwd))

$data = _GUICtrlListBox_GetText($hwd, $index) ; Get check-box's text

$handle = WinGetHandle($data) ;Test it can get check-box's handle?

ConsoleWrite("handle is " & $handle &@CR)

Next

BUT, unfortunately, The output is : "handle is ", it seems that It's also not working here, Of course, It should under condition that my usage of that function is right?

Thanks again, And Sorry for occupying your some much time.

Back to start again? You code is getting handle of List box and Check box.... I preffer you get handle of the main window and then use Pixelgetcolor of reach Checkbox.

In my script if you take a look at the cod again, i am getting handle of the GUI window and then check the color, so my prog is no where identifying it as a checkbox. Hope you got my point.

Or if you dont mind, i would prefer you to post us the program you are using it for and i can try to help you out :)

Thanks,

Mahesh

Share this post


Link to post
Share on other sites

Back to start again? You code is getting handle of List box and Check box.... I preffer you get handle of the main window and then use Pixelgetcolor of reach Checkbox.

In my script if you take a look at the cod again, i am getting handle of the GUI window and then check the color, so my prog is no where identifying it as a checkbox. Hope you got my point.

Or if you dont mind, i would prefer you to post us the program you are using it for and i can try to help you out :)

Thanks,

Mahesh

Hi Mahesh, are you there?

It's another working day now........ :party:

Sorry for my misunderstandings,Now,I got it. Give me some time to try? But In my mind, I still think it's difficult to check or uncheck check-box by some conditions,

For example, There are some rows of check box's text in list-box,

xxx_BV_I_01 May 20, 2009 14:03:30 FAIL

xxx_BV_I_01 May 20, 2009 16:32:43 PASS

xxx_BV_I_01 May 21, 2009 17:03:30 PASS

xxx_BX_C_02 May 20, 2009 10:25:30 PASS

xxx_BN_I_03 May 20, 2009 09:12:33 FAIL

Supposed: all check-boxes are checked by default. The condition is I would like to select PASS status and latest running record, It means I will leave only the rows (check box) meet the condition as checked, With your method, I can now get CHECK state, but how can I handle it to keep these? This is my confusion.

Also The forward description is my requirement for this script.

As for my mess code, I let it alone! Hope to get your pardon :idea:

Thanks

Hunger Hlp

Share this post


Link to post
Share on other sites

Back to start again? You code is getting handle of List box and Check box.... I preffer you get handle of the main window and then use Pixelgetcolor of reach Checkbox.

In my script if you take a look at the cod again, i am getting handle of the GUI window and then check the color, so my prog is no where identifying it as a checkbox. Hope you got my point.

Or if you dont mind, i would prefer you to post us the program you are using it for and i can try to help you out :)

Thanks,

Mahesh

Hi Mahesh, are you there?

It's another working day now........ :party:

Sorry for my misunderstandings,Now,I got it. Give me some time to try? But In my mind, I still think it's difficult to check or uncheck check-box by some conditions,

For example, There are some rows of check box's text in list-box, If you still puzzled by my description, Please see attached file, It's a snapshot of That window.

xxx_BV_I_01 May 20, 2009 14:03:30 FAIL

xxx_BV_I_01 May 20, 2009 16:32:43 PASS

xxx_BV_I_01 May 21, 2009 17:03:30 PASS

xxx_BX_C_02 May 20, 2009 10:25:30 PASS

xxx_BN_I_03 May 20, 2009 09:12:33 FAIL

Supposed: all check-boxes are checked by default. The condition is I would like to select PASS status and latest running record, It means I will leave only the rows (check box) meet the condition as checked, With your method, I can now get CHECK state, but how can I handle it to keep these? This is my confusion.

Also The forward description is my requirement for this script.

As for my mess code, I let it alone! Hope to get your pardon :idea:

Thanks

Hunger Hlp

post-49782-1242881312_thumb.png

Share this post


Link to post
Share on other sites

#14 ·  Posted (edited)

Back to start again? You code is getting handle of List box and Check box.... I preffer you get handle of the main window and then use Pixelgetcolor of reach Checkbox.

In my script if you take a look at the cod again, i am getting handle of the GUI window and then check the color, so my prog is no where identifying it as a checkbox. Hope you got my point.

Or if you dont mind, i would prefer you to post us the program you are using it for and i can try to help you out :)

Thanks,

Mahesh

The following is key code of that part, Could you review for me?

and My solution is in these codes.

Thank you so much for your help, look forward your answer, I'll be here tomorrow.

Sorry, the bad format, I have attached that code.

$hwd = ControlGetHandle("Select Test Cases", "", "[iD:5061]") ; Get listbox handle

$hwdwin = WinGetHandle("Select Test Cases") ; Get window handle

If $hwd = 0 Or $hwdwin = 0 Then

Exit

EndIf

ConsoleWrite("window" & $hwdwin & $hwd & @CR)

If _GUICtrlListBox_GetAnchorIndex($hwd) Then

ConsoleWrite("good" & @CR)

EndIf

$count = _GUICtrlListBox_GetCount($hwd)

;WinMove("Select Test Cases", "", 0, 0)

$isPass = 0

Local $posWin, $posChkBx

Local $ID1, $ID2

Local $color1, $color2, $data

$posWin = ControlGetPos("Select Test Cases", "", "[iD:5061]") ; Get window position

;ConsoleWrite($pos[0] &@CR & $pos[1]&@CR& $pos[2]&@CR& $pos[3]&@CR)

For $index = 0 To $count - 1 Step 0

_GUICtrlListBox_SetCaretIndex($hwd, $index)

$pos = _GUICtrlListBox_GetItemRect($hwd, $index)

;ConsoleWrite($pos[0] & @CR & $pos[1] & @CR & $pos[2] & @CR & $pos[3] & @CR)

$y1 = 328 + $index * 14

$color1 = PixelGetColor(407, $y1, $hwdwin)

$color1 = Hex($color1, 6)

;$posChkBx = _GUICtrlListBox_GetItemRect($hwd, $index) ; Get check box postion

If $color1 = "FFFFFF" Then ; Check state

$data = _GUICtrlListBox_GetText($hwd, $index)

#cs

Remove cases belong to FAIL or INCONCLUSIVE

#ce

If StringRegExp($data, "PASS") = 0 Then

MouseClick("left", 407, $y1, 1)

#cs

Remove repeat cases and keep latest one

#ce

Else

ConsoleWrite("Pass" &@CR)

For $new = $index + 1 To $count - 1 Step 0

_GUICtrlListBox_SetCaretIndex($hwd, $new)

$y2 = 328 + $new * 14

$color2 = PixelGetColor(407, $y2, $hwdwin)

$color2 = Hex($color1, 6)

If $color2 = "FFFFFF" Then

ConsoleWrite("Enter")

$time1 = StringRegExp($data, "(\d+, \d+ \d+:\d+:\d+)", 1)

$ID1 = StringRegExp($data, "(.*)\| Date", 1)

$ID1 = StringStripWS($ID1[0], 2)

ConsoleWrite($ID1 &@CR)

$new_data = _GUICtrlListBox_GetText($hwd, $new)

ConsoleWrite($new_data)

$pos2 = _GUICtrlListBox_GetItemRect($hwd, $index)

$time2 = StringRegExp($new_data, "(\d+, \d+ \d+:\d+:\d+)", 1)

$ID2 = StringRegExp($new_data, "(.*)\| Date", 1)

$ID2 = StringStripWS($ID2[0], 2)

ConsoleWrite($ID2 & @CR)

If StringRegExp($new_data, "PASS") = 1 And StringCompare($ID1, $ID2) = 0 Then

If StringCompare($time1[0], $time2[0]) < 0 Then

; Dis-select $index's case, and continue to find minium case

MouseClick("left", 407, $y2, 1, "")

Else

; Dis-select temprary case and exit current loop: For

MouseClick("left", 407, $y1, 1, "")

ExitLoop

EndIf

EndIf

EndIf

$new += 1

Next

EndIf

EndIf

ConsoleWrite(@CR)

$index += 1

Next

TempraySolution.au3

Edited by HungerHlp

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