SendMessage(ブロックする)を呼び出すことと、WaitForSingleObjectと組み合わせてPostMessageを呼び出すことの違いは何だろうと思っていました。考え?
4 に答える
SendMessage()
may be denied, if you call it from within the context of a COM call, where the COM object lives in an STA (calls are dispatched through the message pump). PostMessage()
is not restricted to adhere to COM apartment rules.
Also, PostMessage()
puts the message on the end of the window's message queue. SendMessage()
bypasses the queue. You can find a lengthier discussion on message queues on Raymond Chen's blog The Old New Thing.
My point is that there is more to the difference between SendMessage()
and PostMessage()
than meets the eye. I really recommend going through Raymond's blog, as he has covered many gotchas over the years.
PostMessage
非同期メッセージングをWaitForSingleObject
実行できるようにします。メッセージを送信したり、他のことをしたり、後で返信を確認したりできます。SendMessage
同期しており、待機する必要があります。
SendMessageは、メッセージキューをスキップして、Windowsプロシージャを直接呼び出すといつも思っていました。PostMessageはメッセージをキューに追加するだけです。
SendMessage is a single API call, therefore less prone to your errors. Go with the built-in rather than rolling your own.