473,471 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to find out if a check box is checked...

tbarto
19 New Member
Hi everybody

For some time I have been working on an UI testing application. The application under test was developed in C#, and my application has been developed in C# as well. I do not have a source code of the application under test, so I use Win API messages and methods. I faced the following problem:

The application under test contains a check box:

Class: WindowsForms10.BUTTON
Text: "Some text"
Style: "Some styles"

After I get a handle to the check box ( I am sure I have the correct handle ) I use SendMessage to retrieve the check box state:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. private const int BM_GETSTATE       = 0x00F2;
  4. private const int BM_GETCHECK       = 0x00F0;
  5. private const int BST_UNCHECKED     = 0x0000;
  6. private const int BST_CHECKED       = 0x0001;
  7.  
  8. int result;
  9.  
  10. result = SendMessage(correctHandle, BM_GETSTATE, 0, 0);
  11.  
  12. or
  13.  
  14. result = SendMessage(correctHandle, BM_GETCHECK, 0, 0);
  15.  
  16.  
My problem is that both SendMessage methods from above always return 0, even if a check box is checked.

Can anybody tell me what is wrong with the code above?

Thanks in advance.
Apr 24 '07 #1
22 13842
amitjul
5 New Member
Hi tbarto,
Me too finding the same problem..if you got its solution, please post it here...i'll be very thankful if you give some time for that.


Hi everybody

For some time I have been working on an UI testing application. The application under test was developed in C#, and my application has been developed in C# as well. I do not have a source code of the application under test, so I use Win API messages and methods. I faced the following problem:

The application under test contains a check box:

Class: WindowsForms10.BUTTON
Text: "Some text"
Style: "Some styles"

After I get a handle to the check box ( I am sure I have the correct handle ) I use SendMessage to retrieve the check box state:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. private const int BM_GETSTATE       = 0x00F2;
  4. private const int BM_GETCHECK       = 0x00F0;
  5. private const int BST_UNCHECKED     = 0x0000;
  6. private const int BST_CHECKED       = 0x0001;
  7.  
  8. int result;
  9.  
  10. result = SendMessage(correctHandle, BM_GETSTATE, 0, 0);
  11.  
  12. or
  13.  
  14. result = SendMessage(correctHandle, BM_GETCHECK, 0, 0);
  15.  
  16.  
My problem is that both SendMessage methods from above always return 0, even if a check box is checked.

Can anybody tell me what is wrong with the code above?

Thanks in advance.
Apr 27 '07 #2
tbarto
19 New Member
Hi tbarto,
Me too finding the same problem..if you got its solution, please post it here...i'll be very thankful if you give some time for that.
Hi amitjul

As far as now I haven't found the solution. I've been working on some other issues. If I am able to get the solution, I will post it here.

Regards
Apr 27 '07 #3
SammyB
807 Recognized Expert Contributor
Hi tbarto,
Me too finding the same problem..if you got its solution, please post it here...i'll be very thankful if you give some time for that.
Googling for SendMessage, I found out the the Net checkbox will always return 0 because it has an extended style of '0000000B'. He later posted that he solved the problem with AccessibleObjectFromWindow but that it was difficult because of poor documentation. He did not post a solution :mad:

AccessibleObjectFromWindow documentation is http://msdn2.microsoft.com/en-us/library/ms696137.aspx

Finally, googling AccessibleObjectFromWindow "C#" shows some working code, but very ugly. If this helps you get a solution, please post it here. Thanks! --Sam
Apr 27 '07 #4
tbarto
19 New Member
Gentleman

I have found how to get access to an UI component with AccessibleOblectFromWindow, however it still does not work for me:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private const int OBJID_WINDOW = 0;
  3.  
  4. [DllImport("oleacc.dll", PreserveSig = false)]
  5. [return: MarshalAs(UnmanagedType.Interface)]
  6. public static extern object AccessibleObjectFromWindow(IntPtr hwnd, uint dwId, ref Guid riid);
  7.  
  8. Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
  9.  
  10. IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
  11. ref uid);
  12.  
  13. object o = accObj.get_accValue(0); //always 0
  14.  
  15. object o1 = accObj.get_accName(0); // works fine
  16.  
  17.  
About the code above: the get_accName works fine for me, it returns a text that the checxbox contains. Unfortunately, get_accValue always returns 0, even if the checkbox is checked. Perhaps any of You can see that there is something wrong?
Apr 30 '07 #5
SammyB
807 Recognized Expert Contributor
Gentleman

I have found how to get access to an UI component with AccessibleOblectFromWindow, however it still does not work for me:

Expand|Select|Wrap|Line Numbers
  1.  
  2. private const int OBJID_WINDOW = 0;
  3.  
  4. [DllImport("oleacc.dll", PreserveSig = false)]
  5. [return: MarshalAs(UnmanagedType.Interface)]
  6. public static extern object AccessibleObjectFromWindow(IntPtr hwnd, uint dwId, ref Guid riid);
  7.  
  8. Guid uid = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
  9.  
  10. IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
  11. ref uid);
  12.  
  13. object o = accObj.get_accValue(0); //always 0
  14.  
  15. object o1 = accObj.get_accName(0); // works fine
  16.  
  17.  
About the code above: the get_accName works fine for me, it returns a text that the checxbox contains. Unfortunately, get_accValue always returns 0, even if the checkbox is checked. Perhaps any of You can see that there is something wrong?
So each control has a GUID? How do you figure out what it is?
Apr 30 '07 #6
tbarto
19 New Member
So each control has a GUID? How do you figure out what it is?
Hi

This is what I've been trying to figure out. I have found that:

Expand|Select|Wrap|Line Numbers
  1. Guid g = new Guid("618736e0-3c3d-11cf-810c-00aa00389b71");
when googling, but I do not exactly understand the "618736e0-3c3d-11cf-810c-00aa00389b71" identifier. I have tried to change that identifier and run the code, but it caused an exception. Since I am not experienced in working with "Guid" I did not find the answer for Your question so far.
Apr 30 '07 #7
SammyB
807 Recognized Expert Contributor
> I have found that:Guid when googling
Hopefully, not at http://www.cafepress.com/cp/moredeta...olorNo=23&pr=F
Apr 30 '07 #8
tbarto
19 New Member
> I have found that:Guid when googling
Hopefully, not at http://www.cafepress.com/cp/moredeta...olorNo=23&pr=F
No, definitely not that one :-)
Apr 30 '07 #9
SammyB
807 Recognized Expert Contributor
No, definitely not that one :-)
Up until now, I have associated GUIDs with tools that are in the registry and used code such as http://msdn2.microsoft.com/en-us/lib...id(vs.80).aspx. But, it looks like from http://msdn2.microsoft.com/en-us/lib...29(VS.80).aspx that there maybe a GUID for each control. It looks like http://msdn2.microsoft.com/en-us/library/ms797957.aspx may be some help in finding the GUIDs. What a rat's nest!
Apr 30 '07 #10
tbarto
19 New Member
Up until now, I have associated GUIDs with tools that are in the registry and used code such as http://msdn2.microsoft.com/en-us/lib...id(vs.80).aspx. But, it looks like from http://msdn2.microsoft.com/en-us/lib...29(VS.80).aspx that there maybe a GUID for each control. It looks like http://msdn2.microsoft.com/en-us/library/ms797957.aspx may be some help in finding the GUIDs. What a rat's nest!
Thanks for the info You've provided. I will try work on that, unfortunately next week, because tomorrow my vacation days start :-)
Thanks one more time for Your help
Apr 30 '07 #11
amitjul
5 New Member
Hi Guys,
That Guid is the constant which you can't change (i dont know the reason :) ). and AccessibleObjectFromWindow is working with preety weird way. i tried to decode it but i failed. ne way, i just found a good solution.

IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
ref uid);

In above code, instead of passing OBJID_WINDOW , try with OBJID_CLIENT

accObj.get_accState(0) will return you some integer value like as below:

public const long UNCHECKED = 1048576;
public const long CHECKED = 1048592;
public const long UNCHECKED_FOCUSED = 1048580; // if control is focused
public const long CHECKED_FOCUSED = 1048596; // if control is focused


so based on that you can easily distiguish that which one is checked (checkbox/radionbutton). Its weird but deadlines are there so.... :)





Thanks for the info You've provided. I will try work on that, unfortunately next week, because tomorrow my vacation days start :-)
Thanks one more time for Your help
May 3 '07 #12
SammyB
807 Recognized Expert Contributor
Hi Guys,
That Guid is the constant which you can't change (i dont know the reason :) ). and AccessibleObjectFromWindow is working with preety weird way. i tried to decode it but i failed. ne way, i just found a good solution.

IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
ref uid);

In above code, instead of passing OBJID_WINDOW , try with OBJID_CLIENT

accObj.get_accState(0) will return you some integer value like as below:

public const long UNCHECKED = 1048576;
public const long CHECKED = 1048592;
public const long UNCHECKED_FOCUSED = 1048580; // if control is focused
public const long CHECKED_FOCUSED = 1048596; // if control is focused


so based on that you can easily distiguish that which one is checked (checkbox/radionbutton). Its weird but deadlines are there so.... :)
So, it all came out guid and you get the t-shirt.! :D
May 3 '07 #13
Plater
7,872 Recognized Expert Expert
Are you trying to capture the checked state of a checkbox in another application that is not your own? Sneaky sneaky.
May 3 '07 #14
amitjul
5 New Member
I am trying to get the state of checkbox/radiobutton/button from a C# application to C# application. so both are different application and both are mine. :)


Where is the T-shirt ?? :)

Are you trying to capture the checked state of a checkbox in another application that is not your own? Sneaky sneaky.
May 4 '07 #15
amitjul
5 New Member
Hi Guys, does anyone knows how to fire any keys. I mean if i want to press ESC key to unload one particular dialog/form How to send message using API in C# ??

I am trying to get the state of checkbox/radiobutton/button from a C# application to C# application. so both are different application and both are mine. :)


Where is the T-shirt ?? :)
May 4 '07 #16
amitjul
5 New Member
No one knows ???? :(
Hi Guys, does anyone knows how to fire any keys. I mean if i want to press ESC key to unload one particular dialog/form How to send message using API in C# ??
May 7 '07 #17
tbarto
19 New Member
No one knows ???? :(
Hi Amitjul

Here is probably a solution You've been looking for. You may use:

System.Windows.Forms.SendKeys.SendWait(keys);

method in the follwing way:

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. [DllImport("user32.dll")]
  4. [return: MarshalAs(UnmanagedType.Bool)]
  5. private static extern bool SetForegroundWindow(IntPtr hWnd);
  6.  
  7.  
  8. IntPtr _handle;  //handle to the destination control
  9.  
  10. public void SendKeys(string keys, int delay) {
  11.  
  12.  
  13. if(!(SetForegroundWindow(_handle)))
  14.     throw new ExternalException("SetForegroundWindow failed");
  15.  
  16. System.Windows.Forms.SendKeys.SendWait(keys);
  17. Thread.Sleep(delay);            
  18. }
  19.  
  20.  
More info about the keys that can be sent to an active control and about SendKeys.SendWait(keys) method You will find here:

http://msdn2.microsoft.com/en-us/lib....sendkeys.aspx
May 7 '07 #18
tbarto
19 New Member
Hi Guys,
That Guid is the constant which you can't change (i dont know the reason :) ). and AccessibleObjectFromWindow is working with preety weird way. i tried to decode it but i failed. ne way, i just found a good solution.

IAccessible accObj = (IAccessible)AccessibleObjectFromWindow(hwnd, OBJID_WINDOW,
ref uid);

In above code, instead of passing OBJID_WINDOW , try with OBJID_CLIENT

accObj.get_accState(0) will return you some integer value like as below:

public const long UNCHECKED = 1048576;
public const long CHECKED = 1048592;
public const long UNCHECKED_FOCUSED = 1048580; // if control is focused
public const long CHECKED_FOCUSED = 1048596; // if control is focused


so based on that you can easily distiguish that which one is checked (checkbox/radionbutton). Its weird but deadlines are there so.... :)
Hi

When running the code i get 0 when a checkbox is unchecked and 16 when it is checked. The values are not exactly the same as in Your code, however I am able to determine if a checkbox is checked or not.

Thanks a lot!!!
May 7 '07 #19
tbarto
19 New Member
Hi

When running the code i get 0 when a checkbox is unchecked and 16 when it is checked. The values are not exactly the same as in Your code, however I am able to determine if a checkbox is checked or not.

Thanks a lot!!!
Sorry,

My fault. Amitjul - everything works exactly as in Your code.

Thanks
May 7 '07 #20
tbarto
19 New Member
I was just wondering. Perhaps any of You Guys knows a way to get access to the PropertyGrid component? The problem is that I am unable to find an info about that. E.g:

http://msdn.microsoft.com/library/de...divcontrol.asp

Under the link above there is an info about many UI components, unfortunately nothing about PropertyGrid :-(
May 7 '07 #21
tbarto
19 New Member
I have found some differences in types on object returend by AccessibleObjectFromWindow. What I mean is that when working on Win XP, the type of the object is System._ComObject , but as I tried on Win 2000 the type was System.Runtime.Remoting.Proxies._TransparentProxy . Obviously, I was unable to cast that type to IAccessible, which caused an exception. Does anybody have any idea about those differences?

Thanks
May 7 '07 #22
vCracker
1 New Member
Hello guys,
I'm working in .net C# to get the URL from IE and Firefox. The IE part was over and I'm stuck up at firefox.
I can't drill down to its address bar(combobox) to get its value. So can anybody help me this problem.
I've gone through your above discussion but not getting what I want.
Ive used accExplorer 2.0 to see the hierarchy of the firefox, and I can see the address bar there but problem is how to access it.
Mar 20 '08 #23

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Rich | last post by:
I have a form with 2 check boxes. One of the check boxes is used to specify that the user is a "primary contact." When I check the primary contact box I want a second box for "standard contact"...
1
by: vncntj | last post by:
i want to enable one listbox and disable the other depending on if i check winter_gala (checkbox) here is my code. <script type="text/javascript"> function check() { if...
1
by: Jim in Arizona | last post by:
I'm having dificulty figuring out how to process multiple check boxes on a web form. Let's say I have three check boxes: cbox1 cbox2 cbox3 The only way I can think of to code the...
10
by: Jim in Arizona | last post by:
I'm having dificulty figuring out how to process multiple check boxes on a web form. Let's say I have three check boxes: cbox1 cbox2 cbox3 The only way I can think of to code the...
12
by: technocrat | last post by:
I am trying to laod 2 tables and set integrtiy on them, but the second tables fails ( both are related and SET INTEGRITY ion first table succeeds) saying constraint violation....is there a way to...
5
by: starke1120 | last post by:
Im creating a check in – check out database for RF guns. I have a table that contains models. ID (primary key) Model A table that contains Gun Details ID (primary key) Model_id...
26
by: ak | last post by:
Recently at an interview i was asked the following question : Assuming the function lookupName is defined, what's wrong with this code (hint: 2 bugs)? const char *getName(const char *c) {...
3
by: Ryanfromscotland | last post by:
Hey there everyone, this is my first post so be nice :-) I have wrote quite a bit so the actual question is written out at the end if you want to skip on and see if you can answer it without the rest...
0
by: Dennis | last post by:
I am wanting to set the Find window to not have the 'Search Fields As Formatted' check box checked. I un-check it but when I close and go back in it is checked again. Is there a way to make it...
1
by: ghjk | last post by:
my php page has 7 check boxes. I stored checked values to database and retrive as binary values. This is the result array Array ( => 0 => 1 => 0 => 1 => 0 => 0 => 1 ) 1 means checked....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.