我需要使用win32Api通过我的适配器点击Windows窗体应用程序按钮。
我已经使用此代码在Windows窗体屏幕上找到了该按钮
childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intbtnx, intbtny));
现在我需要自动点击这个按钮。我不知道该怎么做。需要一些帮助。
到目前为止我已经写了这个,但这只是取了我需要点击它的按钮。
childHwnd = Win32API.FindWindowByPosition(ptr, new Point(intPwdx, intPwdy));
需要单击childHwnd中可用的按钮
您可以使用SendMessage
API
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr SendMessage(IntPtr hWnd, uint msg, int wParam, int lParam);
private const uint BM_CLICK = 0x00F5;
SendMessage(childHwnd, BM_CLICK, 0, 0);
我应该注意,您不会看到按钮的点击动画,只有在您实际点击它时才会出现。 但它应该从其click事件执行代码
编辑
在评论中,OP要求在5秒内延迟SendMessage
,而不冻结应用程序。
这是一个简单的解决方案
来自VS的Toolbox
在表格上放下一个Timer
组件。
设置其属性Interval
to 5000
将其属性Enabled
设置为true
双击事件Tick
并在此处编写此代码
private void timer1_Tick(object sender, EventArgs e)
{
timer1.Enabled = false; // write this if you only want this to happen once
SendMessage(childHwnd, BM_CLICK, 0, 0);
}