Win32API - 通过适配器单击 Winform 应用程序上的按钮

Win32API - Click Button on Winform Application through Adapter

我需要使用 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); 

请注意,您不会看到按钮的点击动画,只有在您实际点击它时才会出现。
但是,它应该执行其点击事件中的代码

编辑
在评论中,OP 要求将 SendMessage 延迟 5 秒,而不冻结应用程序。
一个简单的解决方案是

从 VS 中的 Toolbox 将一个 Timer 组件拖放到表单上。

将其属性Interval设为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); 
}