
本站地址:http://www.bajiao123.com

The Windows Programming Model-----messages
Where do messages come from, and what kinds of information do they convey? Windows defines hundreds of different message types. Most messages have names that begin with the letters "WM" and an underscore, as in WM_CREATE and WM_PAINT. These messages can be classified in various ways, but for the moment classification is not nearly as important as realizing the critical role messages play in the operation of an application. The following table shows 10 of the most common messages. A window receives a WM_PAINT message, for example, when its interior needs repainting. One way to characterize a Windows program is to think of it as a collection of message handlers. To a large extent, it is a program´s unique way of responding to messages that gives it its personality.
Common Windows Messages
Message Sent When WM_CHAR A character is input from the keyboard. WM_COMMAND The user selects an item from a menu, or a control sends a notification to its parent. WM_CREATE A window is created. WM_DESTROY A window is destroyed. WM_LBUTTONDOWN The left mouse button is pressed. WM_LBUTTONUP The left mouse button is released. WM_MOUSEMOVE The mouse pointer is moved. WM_PAINT A window needs repainting. WM_QUIT The application is about to terminate. WM_SIZE A window is resized.
A message manifests itself in the form of a call to a window´s window procedure. Bundled with the call are four input parameters: the handle of the window to which the message is directed, a message ID, and two 32-bit parameters known as wParam and lParam. The window handle is a 32-bit value that uniquely identifies a window. Internally, the value references a data structure in which Windows stores relevant information about the window such as its size, style, and location on the screen. The message ID is a numeric value that identifies the message type: WM_CREATE, WM_PAINT, and so on. wParam and lParam contain information specific to the message type. When a WM_LBUTTONDOWN message arrives, for example, wParam holds a series of bit flags identifying the state of the Ctrl and Shift keys and of the mouse buttons. lParam holds two 16-bit values identifying the location of the mouse pointer when the click occurred. Together, these parameters provide the window procedure with all the information it needs to process the WM_LBUTTONDOWN message.
If you haven´t programmed Windows in C before, it´s instructive to see what the source code for a simple program looks like. The program listed in Figure 1-2 creates a window and responds to WM_PAINT messages by drawing an ellipse in the window´s upper left corner. This code is similar to the source code y
本站地址:http://www.bajiao123.com

