我的应用程序如何找到 Windows 消息的发件人?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/910991/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 12:33:25  来源:igfitidea点击:

How can my app find the sender of a windows message?

windowsmessagekeyboard-hook

提问by mj2008

I have an app which uses a keyboard hook procedure in a library. The wParam in the hook for one message is 255 which we think is "(reserved / OEMClear)". I'd like to work out the source of this message as it causes my application to crash in the library, and given it shouldn't be happening it would be good to identify it. The message comes in repeatedly on only one PC we have - other computers don't see the message at all.

我有一个应用程序,它在库中使用键盘挂钩程序。一条消息的钩子中的 wParam 是 255,我们认为它是“(reserved / OEMClear)”。我想找出这条消息的来源,因为它会导致我的应用程序在库中崩溃,并且鉴于它不应该发生,最好识别它。该消息仅在我们拥有的一台 PC 上重复出现 - 其他计算机根本看不到该消息。

So, is there a way to trace the source of a message sent to a window please, or all those on the system?

那么,有没有办法跟踪发送到窗口的消息的来源,或者系统上的所有消息的来源?

采纳答案by Ana Betts

There is no built-in way to find out who sent the window message, not even win32k keeps track of this; you might be able to find it out with a kernel debugger and a conditional breakpoint.

没有内置的方法来找出谁发送了窗口消息,甚至 win32k 也没有跟踪这一点;您可以使用内核调试器和条件断点找到它。

However, I would argue that you don't really need this information; you need to make your app properly handle anymessage sent to it.

但是,我认为您并不真正需要这些信息。您需要让您的应用程序正确处理发送给它的任何消息。

回答by Aardvark

(I originally suggested using Spy++ or winspector, but they do not hook into the sendingof messages. That doesn't even make sense! A window receives messages but they don't send them, a thread does that. I'll leave my suggestion about using a debugger.)

(我最初建议使用 Spy++ 或 winspector,但它们不挂钩消息的发送。这甚至没有意义!一个窗口接收消息但他们不发送消息,一个线程会这样做。我会留下我的关于使用调试器的建议。)

Sometimes debugging can help. Try downloading the windows PDBfiles and setting a breakpoint that hits only when one of these messages occur. Looking at the call stack at that point can often shed some light on why things are happening. Posted messages and messages send from other processes will foil this approach.

有时调试会有所帮助。尝试下载 Windows PDB文件并设置一个断点,该断点仅在出现这些消息之一时触发。在这一点上查看调用堆栈通常可以阐明事情发生的原因。发布的消息和从其他进程发送的消息将挫败这种方法。

回答by Ozzy

Im not sure if this does what you want it to but have a look at Process Monitor by sysinternals.

我不确定这是否符合您的要求,但请查看 sysinternals 的 Process Monitor。

http:// technet.microsoft.com/en-us/sysinternals/bb896645.aspx

http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx

It shows everything that happens to a process so i assume it catches messages as well. The site was down at time of writing so i couldnt check.

它显示了一个进程发生的一切,所以我假设它也能捕获消息。该网站在撰写本文时已关闭,因此我无法检查。