Donnerstag, 24. März 2011

Messages - The communication

Hello there

In this article I will show how the message system in windows works. The message system is actually used where communication between different thread is necessary. They are used to inform a thread that either something has happened or that the sender needs to know something only the receiving thread can tell. Windows already implements all necessary to work with messages.

A commonly known place where messages are used are windows. If anything happens with the window the operating system sends a message to the application telling it what happened. For example if you click with the left mouse button on the window the system first sends a message WM_LBUTTONDOW and when you release the button a WM_LBUTTONUP message to the application. Thats how an application gets informed that something happened in its window. There are also dozens of other messages that may be sent from a window.

Of course messages are not restricted to windows! You can also implement your own message system using the message API. There are several functions that can be used to work with messages. These are examples:
PostThreadMessage // Sends a message to a thread without waiting what the thread returns!
GetMessage // Takes a message from the current threads message queue. It will not return until a message could be taken
PeekMessage // Takes a message from the current threads message queue. Returns immediatly and indicates if there was message in the queue.

You can find a full list here

Keine Kommentare:

Kommentar veröffentlichen