我有一个线程调用 ::PostMessage(hWnd, [...]);
向主线程发送一条消息,提醒它注意异步操作的结果。
但是,我担心如果线程需要特别长的时间来完成它的操作,当调用 PostMessage
时 hWnd
可能不存在(用户可能已经关闭了窗口)。
MSDN Documentation如果 hWnd
无效,则不会说明任何结果。
如果 hWnd
无效,您是否从经验或其他文档中知道我会发生什么?
最佳答案
Raymond Chen 写道:
- http://blogs.msdn.com/b/oldnewthing/archive/2007/07/16/3885472.aspx
- http://blogs.msdn.com/b/oldnewthing/archive/2007/07/17/3903614.aspx
一些选择摘录:
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/