1-4-1 Windows application composition and programming steps

Source: Internet
Author: User

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

Related Article

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.