要模拟点击其他软件的下拉框,可以使用 WinAPI 中的 SendMessage 函数和 CB_SHOWDROPDOWN 消息。以下是一个简单的示例代码:

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, int Msg, IntPtr wParam, IntPtr lParam);

const int CB_SHOWDROPDOWN = 0x014F;

// 获取下拉框的句柄
IntPtr comboBoxHandle = FindWindowEx(parentHandle, IntPtr.Zero, "ComboBox", null);

// 模拟点击下拉框
SendMessage(comboBoxHandle, CB_SHOWDROPDOWN, (IntPtr)1, IntPtr.Zero);

其中,parentHandle 是目标软件的主窗口句柄。需要注意的是,这种方法只能模拟下拉框的展开/收起操作,无法选择具体的下拉项。如果需要选择下拉项,可以使用 SendMessage 函数和 CB_SETCURSEL 消息。

C# WinForms 模拟点击其他软件下拉框

原文地址: https://www.cveoy.top/t/topic/lC1I 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录