1. Design window class.
When you see the word "design", you will definitely think about it. The window creation process is similar to the automobile manufacturing process. Before producing a model car, we should first design the model car, draw the structure, design the parts, and name it "Audi A8 ". After the design is complete, the car can be produced according to this model.
Of course, when we design a window, it is not as complicated as designing a car. Because Windows has defined the basic properties of a window for us, we only need to set the properties. To achieve the effect of filling blank questions, you can only use struct. The features of the window are defined by the wndclass struct. Wndclass Structure
Body is defined as follows:
Typedef struct _ wndclass {
Uint style; // set the window style
Wndproc lpfnwndproc; // "lpfnwndproc" is a function pointer pointing to a window procedure function (a callback function ).
/* Write an episode here to explain the callback function and window procedure function. The implementation mechanism of the callback function: it is not directly called by the implementer of the function (only provided), but called by the "other party" when a specific event or condition occurs, it is used to respond to this event or condition. (1) define a function (2) the provider registers the function pointer of the callback function to the caller (usually the operating system) during initialization ). (3) When a specific event or condition occurs, the caller calls the function. Window procedure: (1) Assign the function address to the member variable "lpfnwndproc. (2) call "regsiterclass (& wndclass)" to register the window class, so that the system can obtain the address of the window procedure function we have compiled. (3) When the application Program When receiving a message in a window, call dispatchmessage (& MSG) to send the message back to the system. Then the system calls the window process function to process the message. */
Int cbclsextra; // set the additional memory space of the class, which is shared by all windows of the window class.
Int cbwndextra; // set the additional memory of the window to store the unique data of the window.
Handle hinstance; // specifies the instance handle of the "main program" that contains the Window Process
Hicon; // specify the icon handle of the window class. You can use the loadicon function to load an icon resource and return the handle assigned to the icon by the system.
Hcursor; // specify the cursor handle of the window class. You can call the loadcursor function to load a cursor resource and return the handle assigned to the cursor by the system.
Hbbush hbrbackground; // specifies the background paint brush handle of the window class. You can call the getstockobject function to obtain the standard image brush of the system.
Lpctstr lpszmenuname; // specify the menu resource.
Lpctsstr lpsz classname; // specify the name of the window class, just like a new car with a model.
} Wndclass;
2. Registration window class
Just as after designing a vehicle, the vehicle can be produced only after it is approved by the relevant national departments. Similarly, after designing a window class (wndclass), you can call the registerclass function to register it before creating a window of this type. The following is a prototype of the registered function:
Atom registerclass (const wndclass * lpwndclass );
3. Create a window
Use the createwindow function to generate a window of this type.
4. Display and update window
(1) Call the showwindow function to display the window.
bool showwindow (
hwnd, // window handle
int ncmdshow // window display status
);
(2) call the showwindow function to refresh the window
bool updatewindow (
hwnd // created form
);
Friend, if you have any insights, you can add "Sina Weibo"/MSN Oh, starrycheng@live.com, we all discuss together, study together.
Finally, let's add one point for the whole space system.