CodeNinja
CodeNinja

Reputation: 311

Signal event on Window's notification

I am implementing a Reactor design pattern, using a single thread, for asynchronous operations using Windows Events Mechanism.

I faced a problem while trying to combine my reactor to support Windows Notifications (WM_CLOSE, WM_CREATE, WM_DEVICECHANGE...) along with the existing Windows Events.

Thus, my question is: Is it possible to signal an event when a particular window receives a particular notification?

Thanks in advance.

Upvotes: 0

Views: 177

Answers (1)

Remy Lebeau
Remy Lebeau

Reputation: 597136

No, you cannot make Windows signal an event object when particular window messages are received. You would have to catch the messages in your message loop first and then signal the event object yourself as needed.

Otherwise, re-write your message loop to use MsgWaitForMultipleObjects() so it can check for event signals and pending window messages at the same time, and then you can act according to whichever one satisfies the wait on each loop iteration. Just be aware of this gotcha:

MsgWaitForMultipleObjects is a very tricky API

if you specify bWaitAll as true, you may find that your application doesn’t wake up when you expected it to

In this situation, you would set bWaitAll to false and all is well.

Upvotes: 1

Related Questions