【发布时间】:2018-08-24 21:25:36
【问题描述】:
我有一个独特的挑战。我的任务是从我自己的应用程序中操作第三方应用程序的控件,并且我仅限于 .Net 3.5。到目前为止,我可以将文本从剪贴板写入富文本框并单击按钮(感谢 Spy++):
// paste text into Rich Text Box
IntPtr hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.RichEdit20W.app.0.378734a", null);
SendMessage(hwndChild, Msgs.WM_PASTE, 0, IntPtr.Zero);
// click OK button
hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.BUTTON.app.0.378734a", null);
SendMessage(hwndChild, Msgs.BM_CLICK, 0, IntPtr.Zero);
现在我正在尝试访问另一个应用程序中的组合框,以将其数据源内容与从其他地方读取的值进行比较,如果该值与组合框中的值匹配,则在另一个应用程序的组合框中选择该值。我的应用程序是 C#。
我可以像这样使用 user32.dll 方法 FindWindowEx() 在其他应用程序中获取组合框的句柄:
hwndChild = FindWindowEx((IntPtr)handle, IntPtr.Zero, "WindowsForms10.STATIC.app.0.378734a", null);
我使用 Spy++ 查找组合框的类名,但不知道下一步该做什么。我试过这个:
NativeMessage lpMsg = new NativeMessage();
PeekMessage(out lpMsg, hwndChild, 0, 0, 0x0000); // set wRemoveMsg to 0x0000
但通话后 lpMsg 为空。无论如何,这是一个疯狂的猜测。有什么想法吗?
【问题讨论】:
-
stackoverflow.com/questions/11961215/…。接受的答案并不能解决问题。看来,您需要一个 c++ 应用程序,它创建一个钩子,然后从托管代码执行回调
-
这个 cpuld 可以帮助你:pinvoke.net/default.aspx/Constants.CB_GETLBTEXTLEN
-
感谢@oldovets 和@ZorgoZ!