A semaphore message provides a way of signaling, through the message queue, the end of an event. An application uses a semaphore message the same way it uses system semaphore functions-to coordinate events by passing signals. A semaphore message often is used in conjunction with system semaphores.
There are four semaphore messages:
WM_SEM1
WM_SEM2
WM_SEM3
WM_SEM4.
An application posts one of these messages to signal the end of a given event. The window that is waiting for the given event receives the semaphore message when the message loop retrieves and dispatches the message.
Each semaphore message includes a bit flag that an application can use to uniquely identify the 32 possible semaphores for each semaphore message. The application passes the bit flag (with the appropriate bit set) as a message parameter with the message. The window procedure that receives the message then uses the bit flag to identify the semaphore.
To save space, the system does not store semaphore messages in the message queue. Instead, it sets a record in the queue, indicating that the semaphore message has been received, and then combines the bit flag for the message with the bit flags from previous messages. When the window procedure eventually receives the message, the bit flag specifies each semaphore message posted since the last message was retrieved.