Windows SDK Notes (i): basic structure of the program

Source: Internet
Author: User

I. Overview

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)
{
switch (message)
{
case ...
...
case ...
...
}
return DefWindowProc (hwnd, message, wParam, lParam) ;
}
Third, the establishment of the window

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.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.