Window Message

From ReliCodia

(Difference between revisions)
Revision as of 22:01, 6 March 2005
216.231.56.29 (Talk | contribs)
Explained MSG
← Previous diff
Revision as of 22:10, 6 March 2005
216.231.56.29 (Talk | contribs)
User message
Next diff →
Line 18: Line 18:
* time -- time at which message was posted * time -- time at which message was posted
* pt -- cursor position in screen coordinates, when message was posted. * pt -- cursor position in screen coordinates, when message was posted.
-The types of these parameters are the following:+The types of these parameters are as follows:
-* [[API::Window Handle|HWND]] hwnd;+* [[API:Window Handle|HWND]] hwnd;
* UINT message; * UINT message;
* WPARAM wParam; * WPARAM wParam;
* LPARAM lParam; * LPARAM lParam;
* DWORD time; * DWORD time;
-* [[API::Point|POINT]] pt;+* [[API:Point|POINT]] pt;
-==User Message+==User Message==
 +In your program you can send or post Windows messages.
 +Conceptually, when you send a message, you are calling your own [[API:Window Procedure|Window Procedure]]. After you have returned from [[API:SendMessage|SendMessage]], the message have been processed and you can see its result.
 +When you post a message, you append it to the Windows message queue. The message will be executed later, when its turn comes. [[API:PostMessage|PostMessage]] returns as soon as the message is added to the queue.

Revision as of 22:10, 6 March 2005

User input and system notifications are sent by Windows to your application. You get a first look at each message inside the message loop. You can also create messages and send them back to your application, or post them in the Windows message queue.

Message Loop

Every interactive Windows application must have a message loop, usually in its main procedure. The simplest message loop will just retrieve a message from the internal Windows message queue, and dispatch it to your application, where it is picked by your Window Procedure.

MSG  msg;
int status;
while ((status = ::GetMessage (&msg, 0, 0, 0 )) != 0)
{
    if (status == -1)
        throw Win::Exception ("Error in the Windows message loop");
    ::DispatchMessage (&msg);
}				

The MSG data structure has the following data members:

  • hwnd -- handle to the window that will process this message
  • message -- low word: message ID (for instance WM_PAINT), high word: reserved
  • wParam -- message-specific data
  • lParam -- message-specific data
  • time -- time at which message was posted
  • pt -- cursor position in screen coordinates, when message was posted.

The types of these parameters are as follows:

  • HWND hwnd;
  • UINT message;
  • WPARAM wParam;
  • LPARAM lParam;
  • DWORD time;
  • POINT pt;

User Message

In your program you can send or post Windows messages. Conceptually, when you send a message, you are calling your own Window Procedure. After you have returned from SendMessage, the message have been processed and you can see its result. When you post a message, you append it to the Windows message queue. The message will be executed later, when its turn comes. PostMessage returns as soon as the message is added to the queue.