C#真的无法解决用SendMessage获取checkbox状态吗?(难)
public const UInt32 BM_GETCHECK = 0x00F0;
public const UInt32 BM_SETCHECK = 0x00F1;
public const UInt32 BM_GETSTATE = 0x00F2;
private void button4_Click(object sender, EventArgs e)
{
IntPtr hWndParent = FindWindow("WindowsForms10.Window.8.app.0.2bf8098_r16_ad1", "Form3");
IntPtr h = FindWindowEx(hWndParent, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.2bf8098_r16_ad1", "checkBox1");
Message msg = Message.Create(h, BM_CLICK, new IntPtr(0), new IntPtr(0));
//点击hwnd_button句柄对应的按钮
//PostMessage(msg.HWnd, msg.Msg, msg.WParam, msg.LParam);
SendMessage(msg.HWnd, BM_SETCHECK, new IntPtr(0), null);
int i = SendMessage(msg.HWnd, BM_GETSTATE, new IntPtr(0), null);
}
一些API函数的申明我就不写了。我搜遍了所有的资料,有2个问题无解。
1.发送BM_CLICK可以选中checkbox。但是发送BM_SETCHECK就不行。
2.发送BM_GETSTATE无法获取checkbox的状态。
上面两个问题,CSDN也有人问过,帖子太久,一直都没人回答,没有正确答案,就冲着帖子被搜到的点击率,大家能否一起在这个帖子里面解决掉这个问题啊。
谢谢各位
[解决办法]
补充一下,要用这个库需要添加以下引用:
UIAutomationClient
UIAutomationClientsideProviders
UIAutomationTypes
添加名称空间:using System.Windows.Automation;