API Primer Series V-a Serious SDK program

Source: Internet
Author: User

Last article, a brief version of the SDK program was written, and a window was displayed that showed US 1 to 10 of the results, the calculation of the program is not the focus, focus on, one: to let you know the Unicode version of the program and the ASCII version of the program in the programming aspects of the difference, And how to write a common code program. Second: How to use the API or C + + library functions format non-character data to a string display.

However, that fairly simple program, is not a serious SDK program, that is not a pure man, because we have completed an SDK program and the classic steps. Instead, it calls a MessageBox API function, which, though simple to use, is quite complex inside it. How a complex method, specific I do not know, but I know is an SDK program of the classic steps it is all used, what is the classic procedure for writing the SDK program? Listen up, novice friends. Oh, I'll tell you now.

The first step: Register the Window class

Step two: Create a window

Step Three: Message loop

Fourth Step: Write window Message handler function

Above what I said, sounded more professional, I explained below, what is the registration window class? Registering a window class is to use a window class structure (WNDCLASSEX) to describe a class of windows that have the same properties, that is, the values you specify in the structure wndclassex. Windows that are created with this window class have these attributes. As for what the WNDCLASS can describe, here's what you need to know to describe the category of a window using a struct called wndclassex.

Create a window should be better understand it, is to create a specific window, as if it is a nonsense. This means that the window is created from a window class and is not made out of thin air. It means that you want to create a window, then you have to have a registered window class.

For the first two steps, I would like to make a analogy, like you want to build a car, then the first step is what? Of course the design drawings, the drawings on the description of what the car features. Then the second step is to create a concrete visible car based on this drawing. So I said the registration window class is like the design window of the drawing, and then based on the window of the drawing to create a specific window. All say so, should understand it ~ ~

As for the message loop, the window created is likely to happen a lot of things at any time, so how do these things happen to inform you?  For example, window minimized, window size changed, how to inform you? In fact, it is through the message loop constantly to get the things that happen to the window, and then send the message to us in the form of the window message processing function to be introduced later.

The message processing function is that our programmer is responsible for writing code to deal with specific messages, of course, you can not process, to the system's default processing functions to deal with.

For these two steps, I also make an analogy. A message loop is like a total sensor of a car, it is a continuous flow of things inside the car in the form of messages through the dashboard to convey to the driver, the driver based on specific things to take specific actions, of course, you can not operate, indifferent, for Windows messages, not operation is nothing , and for those who drive, the consequences of not doing so are difficult to say. Here, the total sensor is equivalent to the SDK program's message loop, constantly sending messages, and the driver is the equivalent of window message processing functions, responsible for processing various messages. Understand, do not understand the following specific procedures to see, but also need to have the last glimmer of hope can let you suddenly.

After talking about the classic steps of the Serious SDK program, we went into the formal code phase to further consolidate knowledge by combining the above theory with the code. I talk step-by-step and gradually write a register window class, create a window, with a message loop, and write their own message processing procedures.

First, give the program framework

/* BY beyondcode */

#include <windows.h>

#include <tchar.h>


LRESULT CALLBACK WinMessageProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam );


int WINAPI _tWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nShowCmd )

{

return 0;

}

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.