WINAPI:查看来自其他进程的消息 [英] WINAPI: Look at messages from other process

查看:345
本文介绍了WINAPI:查看来自其他进程的消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Windows API的新手,想知道如何窥视另一个进程收到的消息。作为一个例子,我想得到HWND的,说,记事本,并窥视发送到这个窗口的所有消息。我用C / C ++编码。

I'm quite new to the Windows API and would like to know how to peek at messages another process receives. As an example, I would like to get the HWND of, say, notepad and peek at all messages that are sent to this window. I code in C/C++.

谢谢

推荐答案

可以使用 SetWindowsHookEx 函数, WH_CALLWNDPROC 或其他类型的钩子,这里是一个示例。

You can use SetWindowsHookEx function, with WH_CALLWNDPROC or some other type of hook, and here is an example.

WH_CBT 您的好机会,因为您可以从中获取 HCBT_CREATEWND 代码,并且在之前创建一个窗口,因此您可以提供自己的窗口代替真正的窗口,然后能够得到所有的消息。

The WH_CBT can give you great opportunities because you can get a HCBT_CREATEWND code from it and it's sent to you right before a window is created, thus giving you a possibility to provide your own window proc instead of the real one and then be able to get all messages possible with it.

记住,更大的可能性也意味着更大的责任。说你子类化一些窗口,提供你的窗口触发器,如果​​你的应用程序设置一个钩子退出,下一件你会看到的是应用程序,你的消息你偷看,崩溃,如果你没有把地址原窗口proc回到它所属的地方。这种挂钩的好处是能够等待某个窗口(例如使用某个窗口类或名称)被创建并在之前 您感兴趣的任何窗口都将被创建。

Remember though, greater possibilities also mean greater responsibility. Say you "subclassed" some window, providing your window proc, if your application that set a hook exits, next thing you'll see is the application, whose messages you were peeking at, crashes if you didn't put the address of the original window proc back to where it belongs. The benefit of this kind of hooking is the ability to wait for a certain window (say with a certain window class, or name) to be created and get into that process before any window you're interested in would even be created.

这篇关于WINAPI:查看来自其他进程的消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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