Windows programs have a relatively fixed structure, and for writers, the entire process is not written, and most of the process is done by the system.
As long as the program in a certain format to fill in the system left to customers that small part.
What needs to be done are:
The definition of window class, the establishment of windows, the writing of message functions, the message loop.
Second, the message processing function
The Windows program is event-driven, and for a window, most of its routine maintenance is maintained by the system. None of the windows have a message handler function.
In the message handler function, the incoming message is processed. The system also has its own default message handler function.
The client writes a message handler that associates the message handler function with the window before the window is established. This way, whenever a message is generated, the message handler function is invoked.
Typically, customers do not process all of the messages, but only the messages they are interested in, and others are sent back to the system's default message handler.
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)Third, the establishment of the window
return DefWindowProc (hwnd, message, wParam, lParam) ;
The client needs to create a window of its own that will get the window handle (HWND) returned by the system, followed by the operation on the window for the handle.
1. Register window class
Before you set up the window, you need to make the relevant properties of this window, the most important thing is to associate the message processing function you defined with the window, and other properties include: menu, Icon, etc.
This property specifies that the step is done by specifying the window class.
For the window you set up, this "window class" needs to be made by itself, by populating a WNDCLASS structure and then registering with the system.
For some special windows, such as buttons and other controls, their behavior is the system has been set up, so do not need to register themselves, directly using the corresponding "window class" name on the line.
2. Create a window
When you create a window, the registered window class name is passed in as a parameter.
Thus, when there is a message for the window, the message handler function specified in the window class is invoked, where it is processed.