如何将事件挂接到其他应用程序中的 Windows 控件 [英] How to hook an event to a windows control in other application

查看:24
本文介绍了如何将事件挂接到其他应用程序中的 Windows 控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须检测我没有源代码的应用程序中的组合框何时发生了变化.这个想法是将一个事件挂接到这个控件上,当事件触发时,获取控件的选定值.我用谷歌搜索过,但我刚刚找到了如何挂钩窗口(如何挂钩window),当标题文本改变时.我可以获取控件的句柄 (FindWindowEx),但是,我不知道如何将事件挂接到控件上,如果有人可以帮助我,请帮我.

I have to detect when a combobox from an application I have not source code, has changed. The idea is to hook an event to this control, and when the event fires, get the selected value of the control. I have googled but I just have found how to hook with a window (How to hook on a window), when the header text change. I can get the handle of the control (FindWindowEx) but, I have no idea how to hook an event to the control, please guys if any can help me with this.

推荐答案

您可以查看 SendMessage API.DDE 是 IPC 的旧方法,但它仍然适用于 .net.

You can look into the SendMessage API. DDE was an old method of IPC but it still works with .net.

作为一种廉价简单的方法,只需创建一个带有 guid + '|' 的表单+ 文本框的句柄作为 Text 属性.当您的应用运行时,只需加载表单但不显示它(也将其从任务托盘中隐藏).

As a cheap easy method, just create a form with a guid + '|' + the handle of a text box as the Text property. When your app runs just load the form but don't show it (hide it from the task tray as well).

您的其他应用程序可以使用标题中的预定 guid 在第一个应用程序表单上 FindWindowEx 并获取表单上文本框的句柄(使用管道字符或其他东西将其与 guid 分开).

Your other app can FindWindowEx on the first apps form using the predetermined guid in the header and also get the handle to the textbox on the form (seperate it from the guid with a pipe char or something).

现在只需将 SendMessage(WM_SETTEXT) 发送到文本框 hwnd(给它用户在组合框中选择的值).如果您将事件处理程序放在 text_changed 事件上,它将在您的第一个应用中触发.

Now just SendMessage(WM_SETTEXT) to the textbox hwnd (give it the value the user selected in the combobox). If you put an event handler on the text_changed event it will fire in your first app.

这篇关于如何将事件挂接到其他应用程序中的 Windows 控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆