Raouldukey 0 Newbie Poster

I am writing a program to control other applications that are running. Essentially an automation UI program. I am using a combination of AutoIt and basic windows API calls (sendcommand). I am able to do almost everything that I need (read/write textboxes, labels, click buttons/checkboxes/radiobuttons) However, I cannot seem to work out how to determine if a radiobutton or checkbox is checked or not. I have searched and searched the web and cannot come up with an answer. I believe the Sendmessage(hWnd,BM_GetChecked,0,0) command will work with older Win32 controls, but only returns 0 with newer .NET controls. People talk about using Iaccessible interface, but I cannot figure out how to make it work, nor do I have the code for the other applications if I have to make changes there. So, I would greatly appreciate it if someone could put together a snippet of code that could identify if a checkbox/radiobutton is checked or not on a different application.

The following is what I have to determine the hWnd of the control and try to sendmessage to it. I can sendmessage(hWnd,BM_Click,0,0) just fine to click on it, but I cannot not determine if checked already.

I am not stuck on doing it this way at all if someone can show me another way to do it...


Public Class Form1

Declare Auto Function SendMessage2 Lib "user32.dll" Alias "SendMessageA" (ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As IntPtr, ByVal lParam As IntPtr) As Int32


Private Declare Auto Function FindWindow Lib "user32.dll" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) As IntPtr

    Private Declare Auto Function FindWindowEx Lib "user32.dll" ( _
    ByVal hwndParent As IntPtr, _
    ByVal hwndChildAfter As IntPtr, _
    ByVal lpszClass As String, _
    ByVal lpszWindow As String _
    ) As IntPtr

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim returnvalue As Integer

        Dim hWnd As IntPtr = FindWindow(vbNullString, "TestFormName")
        If hWnd.Equals(IntPtr.Zero) Then
            MessageBox.Show("no window")
        End If


        Dim hWndButton As IntPtr = _
        FindWindowEx(hWnd, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.2bf8098_r20_ad1", "RadioButton1")
        If hWndButton.Equals(IntPtr.Zero) Then
            MessageBox.Show("no control")
        End If

        'once you have the right handle, try to send bm_click to see if checked
        returnvalue = SendMessage2(hWndButton, BM_GETCHECK, 0, 0)


    End Sub

end class
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.