I am writing an application to interface two other existing applications. I'm new to C# so this is quite the challenge for me. My current issue that I have yet to find an answer for is whether a checkbox is checked or not. I was trying to use UIAutomation but I couldn't figure out how to get it working. When I check the checkbox using UISpy it indicates that the checkbox is a pane. after much searching over 2 days I couldn't find out how to get the information for a checkbox as a pane. I was thinking that pInvoke would do the trick but I haven't had any luck with that either. Here is what I have tried:
var ischecked = NativeMethods.SendMessage(variables.allCNumbers[29].Hwnd,BM_GETSTATE, IntPtr.Zero, IntPtr.Zero);
MessageBox.Show(variables.allCNumbers[29].Hwnd.ToString()); // This has a value
MessageBox.Show(ischecked.ToString()); // This always shows 0 whether the checkbox is checked or not
Here is the UIAutomation I have tried:
AutomationElement rootElement = AutomationElement.RootElement;
Automation.Condition condition = new PropertyCondition(AutomationElement.ClassNameProperty,"TMainForm_ihm" );
AutomationElement appElement = rootElement.FindFirst(TreeScope.Children, condition);
AutomationElement workspace = appElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Workspace"));
AutomationElement card = workspace.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Card"));
AutomationElement pagecontrol = card.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.ClassNameProperty, "TRzPageControl"));
AutomationElement cardnumber = pagecontrol.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Card number"));
if(cardnumber != null)
{
Automation.Condition usecardCondition = new PropertyCondition(AutomationElement.AutomationIdProperty, "25232366");
AutomationElement usecard = cardnumber.FindFirst(TreeScope.Children, usecardCondition);
MessageBox.Show("usecard: " + usecard.Current.ControlType.ProgrammaticName); // This returns "ControlType.Pane"
//TogglePattern tp1 = usecard.GetCurrentPattern(TogglePattern.Pattern) as TogglePattern; <- This throws an error: An unhandled exception of type 'System.InvalidOperationException' occurred in UIAutomationClient.dll Additional information: Unsupported Pattern.
//MessageBox.Show(tp1.Current.ToggleState.ToString());
}
Any help is greatly appreciated.