正确使用 NativeWindow 实现 Windows 挂钩

发布于 2024-08-16 09:59:04 字数 305 浏览 7 评论 0原文

我没有太多的 C++ 背景,但已经成功挂接了一个窗口并将其消息转换为我的应用程序可以使用的引发事件,我从继承 NativeWindow 并覆盖 WndProc 开始,并确定了我感兴趣的消息,WM_VSCROLL 和 WM_HSCROLL实例。

首先,是否有完整的实现可以引发所有常见事件,例如 keypress、keydown、keyup、mousemove、mousedown、vscroll、hscroll、vresize、hresize 窗口。我有兴趣确保我正确地实施了该课程。

其次,我如何正确限制 NativeWindow 产生的事件,以限制实现的繁琐。

I dont have much of a C++ background but have successfully hooked a window and converted its msgs into raised events that my application can consume, Ive started by inheriting from NativeWindow and overriding WndProc and have determined the msgs that im interested in, WM_VSCROLL and WM_HSCROLL for instance.

Firstly are there any full implementations out there that raise all the usual events, like keypress,keydown,keyup,mousemove,mousedown,vscroll,hscroll,vresize, hresize of the window. Im interested in making sure that ive implemented the class correctly.

Secondly how do I properly throttle the events produced by my NativeWindow, as to limit the chattiness of the implementation.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

櫻之舞 2024-08-23 09:59:04

我假设您正在谈论在另一个应用程序中挂钩窗口。这是一个不平凡的问题,wparam 和 lparam 参数可能包含指针而不是简单值。然而,这些指针仅在您挂接的窗口的进程的虚拟内存空间中有效。忽略这一点将为您带来 AccessViolation 异常。

您必须 P/Invoke ReadProcessMemory() 才能读取指向的结构。这需要针对每条单独的消息完成,您不能指望通用实现。当您挂接一个重要的窗口(如 ListView 或 TreeView)时,这可能会变得非常棘手。

I assume you are talking about hooking a window in another application. That's a non-trivial problem, the wparam and lparam arguments may contain pointers instead of simple values. Those pointers are however only valid in the virtual memory space of the process who's window you hooked. Ignoring this will buy you an AccessViolation exception.

You have to P/Invoke ReadProcessMemory() to read the pointed-to structure. That needs to be done for each individual message, you can't count on a generic implementation. That can get quite hairy when you hook a non-trivial window like a ListView or TreeView.

咽泪装欢 2024-08-23 09:59:04

大多数执行此操作的程序都使用 DLL 注入来处理拥有该窗口的进程内部的事件。当然,您不能将托管代码注入到另一个进程中,而只能将本机代码注入到非常小心的不要弄乱应用程序状态的代码中。

你想实现什么目标?挂钩其他应用程序的窗口应该是最后的手段。

Most programs that do this use DLL injection to handle the events from inside the process that owns the window. Of course, you mustn't inject managed code into another process, only native code that is very careful not to mess up the application state.

What are you trying to accomplish? Hooking other applications' windows' should be the last resort.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文