Main content: Introduction to the composition of Windows applications and programming steps
1. Composition of the application
<1> A complete application typically consists of five types of files
1. SOURCE Program Files
2. Header files
3. module definition File
4. Resource Description File
5. Project document (also referred to as Project Document project)
<2> Source program Composition structure
1. Entry function WinMain
The <1> entry function is the entry for all programs, similar to the main function
<2> completion of definition and initialization, generating message loops
2. Window function WndProc
<1> window process to complete some message loop response
This is the basic framework for Windows applications
in this framework, various data types, data structures, and corresponding functions are included.
2.WinMain function
functions of the WinMain function
<1> Registering window classes, creating windows and performing necessary initialization
<2> Enter the message loop, and the received message calls the appropriate process
<3> terminating a program when a message loop is retrieved to Wm_quit
the basic composition of WinMain function
<1> Function description (function parameter)
int WINAPI WinMain
(hinstance hthisinst,//application current instance handle
hinstance hprebinst,//Application Other instance handle
LPSTR lpszcmdline,//Pointer to program command-line arguments
Int ncmdshow)//integer value identifying the way the window is displayed when the application starts executing
<2> Initialization
1. Window class definition
define the form and function of the window
LoadIcon, LoadCursor and getstockobject, etc.
2. Registration of window classes
The window class must first be registered and then used
registerclass
3. Create a Window instance
CreateWindow
4. Display window
ShowWindow and UpdateWindow
<3> Message Loops
3. Window function WinProc
The <1> window function defines the response of the application to the different messages received
It also includes the processing of all the messages that may be received .
<2>winproc Architecture---> switch-case structure
Prototypes:
LRESULT CALLBACK WndProc (HWND hwnd, UINT message, WPARAM WPARAM, LPARAM LPARAM) {
switch (message) {//message is a message that is identified
Case ...
Break ;
... ..
Case Wm_destroy:
postquitmessage (0);
Default:
//provides default handling of messages for undefined processing
return DefWindowProc (hwnd, message, WParam, lParam);
}
return 0;
}
in the message handler segment, Wm_destroy is generally handled .
the message is emitted when the window is closed,
it sends an WM_QUIT message to the application, requesting to exit the handler function,
void postquitmessage (int nexitcode);
//nexitcode The exit code for the application
<3> Data Type introduction
LRESULT: The data type of the return value of the message processing result, actually a long
CALLBACK: Indicates that this function is called to the system, also called a callback
1-4-1 Windows application composition and programming steps