I am trying to determine the state of a checkbox in an external program from a VB.Net WinForm application. I used Spy++ to get the handle of the checkbox. I convert the handle from hex to decimal, and enter it into a textbox (I automatically extract the handle in my full application). I can toggle the checkbox from my program, so I know i have the correct handle. However I can not seem to GETSTATE or GETCHECK using SendMessage. I was not sure which I should be using, but they both always return 0. Here is my module code:
and my form codeCode:Imports System.Runtime.InteropServices Module Module1 Public Const BM_CLICK = &HF5 Public Const BM_GETCHECK = &HF0 Public Const BM_GETSTATE = &HF2 <DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> Private Function SendMessage(ByVal hWnd As IntPtr, ByVal Msg As UInteger, ByVal wParam As Integer, ByVal lParam As Integer) As Integer End Function Sub toggle(hwnd As IntPtr) SendMessage(hwnd, BM_CLICK, 0, 0) End Sub Function GetCheck(hwnd As IntPtr) As Integer Return SendMessage(hwnd, BM_GETCHECK, 0, 0) End Function Function GetState(hwnd As IntPtr) As Integer Return SendMessage(hwnd, BM_GETSTATE, 0, 0) End Function End Module
Any help would be appreciatedCode:Public Class Form1 Private Sub btnToggle_Click(sender As Object, e As EventArgs) Handles btnToggle.Click Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr) toggle(hwnd) End Sub Private Sub btnGetStatus_Click(sender As Object, e As EventArgs) Handles btnGetStatus.Click Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr) lblState.Text = GetState(hwnd).ToString End Sub Private Sub btnGetChk_Click(sender As Object, e As EventArgs) Handles btnGetChk.Click Dim hwnd As IntPtr = CType(TextBox1.Text, IntPtr) lblCheck.Text = GetCheck(hwnd).ToString End Sub End Class




Reply With Quote
