Freiza Grandmaster Cheater
Reputation: 22
Joined: 28 Jun 2010 Posts: 662
|
Posted: Thu Feb 23, 2012 2:33 am Post subject: Win32 Tutorial Part 2c- Creating Window |
|
|
Some theory :
In windows operating system architecture we share resources. Windows is an multitasking operating system. It can run many process concurrently.
When an event occurs windows operating system keep track of that event as message in their message Queue. And sends those messages to the running application/processes. Then application sends the message to its appropriate window.
To understand the working scenario of windows operating system. Let us take an example:
1) Suppose we have two powerpoint window running at the same time. Namely X and Y.
2) X is active and Y is inactive.
3) We press a key from the keyboard. (Windows operating system will recognize this key press as keypress event and will store it in its message queue. Since our window X is active so windows operating system will recognize and send this message to window X.
4) As we notice powerpoint have multiple area. Out of which one is main working area and many other areas. Each of these area is considered different window. Suppose keypress is designated to main working window. Powerpoint application will receive messages from operating system and again forward message to appropriate window.
Note:- Not all messages are passed this way. But in context of our tutorial this is true.
Q) So, How is messages retrieved by application from Operating system.
Ans) Through Message loops.
| Code: | MSG msg = { };
while (GetMessage(&msg, NULL, 0, 0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
|
Messages are retrieved from operating system's message queue with the help of GetMessage function.
First parameter - when message is retrieved from operating system it is stored in msg structure.
Second parameter - we pass HANDLE of the window we want the message to be processed. Suppose if there are n window in an application. and we are only
interested in retrieving message for only a particular window. then we pass HANDLE of that window here. If it is set to NULL
that means all the window in current application are eligible for receiving messages.
3rd and 4th parameter - We ignore it since it is not relevant to our beginners tutorial.
***************************************************************************
MSG Structure is an important structure it also have some important members.
typedef struct tagMSG { // msg
HWND hwnd;
UINT message;
WPARAM wParam;
LPARAM lParam;
DWORD time;
POINT pt;
} MSG;
it is documented like this is msdn.
First member contain handle to window to whom the message belongs.
second parameter - Is a unsigned integer that uniquely identifies the type of message. (for ex:- keypress message, left mouse button down message, window move message etc.)
3rd and 4th parameter gives additonal information about messages (for ex:- for mouse messages it will contain screen coordinate etc. We will discuss about it later in details.)
5th - the time when the message was posted
6th - Contains the Coordinates of the message
We will use top four messages in this tutorial.
|
|