In general, the so-called WIN32 application development, is in the C language level, directly using the WIN32 API (application Programming Interface: System open, to the programmer to use the interface. To develop Windows applications or System programs. Although there are not many people who develop applications directly with the Win32 API, a deep understanding of the principles of Windows system design is still the only way to become a master of Windows development.
the so-called Win32, in fact, is an API specification, which corresponds to the UNIX system programming interface standard POSIX . The following is the basic idea for direct WIN32 SDK programming or a framework analysis:
a Windows program is divided into program code and UI (user interface) resources two parts, the last two Interface to the RC compiler compiled into a complete EXE file. The so-called UI resource refers to the Function menu, dialog box appearance, program icon, cursor shape, and so on. The actual content (binary code) of these UI resources is generated by various tools and exists in various extensions, such as. ico. bmp. Cur, and so on. Programmers must describe them in a so-called resource description file (. rc). RC compiler (RC. EXE) to read the description of the RC file, create a single. RES file in all the UI resource files, and then combine with the program code, which is a complete Windows executable file.
Windows programs will invoke a number of functions to implement some of their functions, which can be divided into C runtimes and the Windows API , and the APIs are provided by the operating system itself, including GDI32.LIB, USER32. LIB, KERNEL32. LIB, COMDLG32. LIB, TH32. LIB, and so on, the top three is the Import function library for the three major Windows modules.
The message mechanism for Windows is " message based, event-driven ." , that is, the Windows program is dependent on external events to drive , that is to say: The program constantly waiting for messages, external events in the form of messages into the system into the appropriate queue, and then the program calls the GetMessage API to obtain the corresponding message and make the corresponding processing. Windows are used to receive and process messages, and each window corresponds to a function to process the message, and the programmer must design this window function (Windows procedure).
The implementation of the Win32 application (SDK) is mainly divided into the following steps:
First, WinMain function
the main () function is the entry point of the C program, and the WinMain function is the entry point of the Windows program,
Second, MSG structural body
defines a MSG structure, which is a data format that is built-in to Windows:
Third, registration window
registerclass () Completes the Registration window class function, sets the window the property, including the border, the color, the title, the position and so on.
Four, create a window
the CreateWindow function can be used to create a parent window, pop-up window, and child windows that can determine the window class, window caption, window style, size, and initialization position when creating a window.
Five, display window
When you create a window, you need to use ShowWindow to display the window.
Six, refresh the window
Call the UpdateWindow function to refresh the window.
Seven, message circulation
after the initialization is completed, WinMain into the so-called message loop, using the while loop, constant GetMessage, and then using TranslateMessage to convert the message to the Windows function to handle the message by DispatchMessage.
Eight, get the message
the GetMessage function gets the message from the message queue, and if there is no message in the message queue, the function waits for the message.
IX. Conversion of messages
converting a particular message to a different message, such as a wm_keydown and Wm_keyup message in a message queue, means that the user presses a few keys on the keyboard at the same time, and TranslateMessage converts it to a WM_CHAR message.
X. Sending messages to callback functions
dispatchmessage to the window function of the window through the help of the user module, but DispatchMessage does not specify the function name, but it can send the message to the past, because when the message occurs, the OS has been based on the current state, It identifies the owning window, and the window class that the window belongs to is also clear.
Xi. WinMain function return value
return msg.wparam; Returns the value of the wparam in the structure variable MSG.
12. WindowProc window function
the Life pivot in the window: Window function WindowProc. WindowProc is a callback function that often uses switch/case to determine the type of message to determine how it is handled.