【发布时间】:2020-10-19 14:48:32
【问题描述】:
我正在尝试自动化我没有源代码的遗留应用程序上的一些东西。所以我实际上是在尝试使用 Windows API 来单击我需要的按钮。
有一个msvb_lib_toolbar 类型的工具栏,如下所示:
我可以通过使用以下代码来处理它(我认为):
IntPtr window = FindWindow("ThunderRT6FormDC", "redacted");
IntPtr bar = FindWindowEx(window, IntPtr.Zero,"msvb_lib_toolbar",null);
查看文档,看来我应该可以使用 SendMessage 和 TB_PRESSBUTTON 消息来单击这些按钮:
[DllImport("user32.dll")]
public static extern int SendMessage(int hWnd, uint Msg, int wParam, int lParam);
但是,我不确定如何设置 wParam 和 lParam 以单击栏上的所需按钮。文档似乎也没有多大帮助。
您能建议吗?
基于cmets,我也试过UIAutomation。我可以使用以下代码找到工具栏:
AutomationElement mainWindow = AutomationElement.RootElement.FindFirst(TreeScope.Children, new PropertyCondition(AutomationElement.NameProperty, "Migration Expert"));
AutomationElement toolbar = mainWindow.FindFirst(TreeScope.Subtree, new PropertyCondition(AutomationElement.ClassNameProperty, "msvb_lib_toolbar"));
但是从这里开始,我不确定该怎么做,因为 Spy++ 没有显示该对象的更多子对象:
看着这个AutomationElement 的Current 属性,我看不到任何东西跳出来,但BoundingRectangle 似乎表明我找到了正确的元素。
使用inspector.exe 也不表示工具栏上有任何子项。
【问题讨论】:
-
我不知道长度或宽度是否真的很重要。我的窗户会在短时间内出现并关闭,大小无关紧要。请参阅:pinvoke.net/default.aspx/user32/…
-
这是您的问题和解决方案:You can't simulate keyboard input with PostMessage。
-
@IInspectable 我不想模拟键盘输入
-
@RitaHan-MSFT 是的,它把整个工具栏看作一个东西,没有选择按钮
标签: c# winapi ui-automation user32