windows -::PostMessage 到一个无效的 hWnd

标签 windows winapi

我有一个线程调用 ::PostMessage(hWnd, [...]); 向主线程发送一条消息,提醒它注意异步操作的结果。

但是,我担心如果线程需要特别长的时间来完成它的操作,当调用 PostMessagehWnd 可能不存在(用户可能已经关闭了窗口)。

MSDN Documentation如果 hWnd 无效,则不会说明任何结果。

如果 hWnd 无效,您是否从经验或其他文档中知道我会发生什么?

最佳答案

Raymond Chen 写道:

一些选择摘录:

It so happens that boatloads of programs (and "boatloads" is a technical term) contain bugs where they use window handles after the window has been destroyed. When a window handle is re-used, that program sends a message to the window it thinks is still there, but instead it sends the message to a completely unrelated window. This doesn't bode well for the program, and it usually doesn't bode well for the new window that received the message by mistake either.


We left off our story last time by raising the problem of programs that send messages to windows that have already been destroyed and how window handle re-use exacerbates the problem. Although this is clearly a bug in the programs that use window handles after destroying the window, the problem is so widespread that the window manager folks in Windows NT decided to take a more proactive approach.

关于windows -::PostMessage 到一个无效的 hWnd,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17096073/

相关文章:

python - 简单的 Python 脚本无法正确执行

c# - GetShortPathNameA 在 C# 中不起作用

windows - 如何解决 bash 编码问题?

winapi - 如何从 IWebBrowser2 获取 documentenCompleted 事件?

winapi - GetTickCount() 实际测量什么?

java - 如何将系统属性传递给作为 Windows 服务运行的 Tomcat 7 中托管的 Web 应用程序?

c - 使用 ZwQuerySystemInformation 获取 SystemKernelDebuggerInformation

winapi - 创建 "virtual"文件并执行

windows - 为什么最大化的 Delphi 窗体比 GetSystemMetrics 值宽 8 像素且高于 GetSystemMetrics 值?

python - Windows 7/Vista 进程管理 - 如何在长时间空闲后启动外部程序?