002_GUI program case study

A, GUI application development overview

1, modern operating system provides native SDK (Software Development Kit) supports GUI application development.
2, GUI application development is the mainstream technology on modern operating systems.
3, the same GUI development on different operating systems principle, but a different GUI SDK.

Two, GUI application development principles

1, GUI program at run time creates a message queue.
2, the operating system kernel will be translated into a corresponding user program message (when the user operates the computer, the operating system kernel will detect the user's operating system kernel will generate a program to a user message according to the current operation, so this a program message to the application that has focus).
3, the program in real time during operation needs to process messages in the queue.
4, when there is no message in the queue, the program at a standstill.

Different operating systems support the same principles GUI development

Three, GUI application development nature

GUI application development is actually two major work to be done:

1, the code used to create the program window and the window element (say white is the program to create a GUI interface).
2, the message handler respond differently to the message according to a program.

Four, GUI application development example

Five, GUI application development early experience



STEP 1: the main window styles


complement: in which Windows (L followed by a string) indicating that the character is a wide character, i.e. not to ASCII, UTF-8 encoding, or instead of unicode.

What is Unicode?
Unicode is the same as the ASCII character encoding method, it takes two bytes (0000H-FFFFH), hold 65,536 characters, which can accommodate encode all the world's languages. In unicode, all characters are handled by a character that has a unique unicode code.
Use Unicode encoding so that the project can support multiple languages at the same time, the international engineering. I.e. without incurring distortion in a different language system.

Step 2: Create the main window

Step 3: Create an element

Step four: display window on the screen

Step Five: provided by the operating system (the GetMessage) function to the application message queue messages taken out, taken out after translation

Compile and run tests:

this first GUI applications already up and running, you can care Datuo small, can be minimized, can be maximized, it has standards of conduct of the Windows GUI applications.
Then click on the button there is no response, according to the principle known GUI application development, when our users to do a press operation, the Windows operating system will generate a message in accordance with this operation, the generated message into us application message queue will eventually be sent to the message processing function. But sending a message handler as if nothing had happened, because there is no deal with this message in the message processing function inside

Top right, click the Close button, you will find the GUI application or running, and not directly shut down because of the default message handler operating system provided by (used to treat behavior of the vast majority of windows GUI application should have) the GUI application will switch to the program running in the background.

1. Add the code Close

Why (PostQuitMessage) function? Each application will return a value to the operating system, then the call is to return to the operating system parameters 0, and quit themselves. This is to tell the operating system Zero current application is a normal exit.

Run again, click the Close button is the real withdrew.

2. Add code message button processing
by creating id value known elements which the user presses a button. Action can also be obtained by id value of the message in the lower third parameter, the third parameter of the high users get real

run again

Six, just to finish with MFC applications

1. Create a new MFC project


MFC framework has been set to achieve a complete classic mode GUI application development, it is for the development of the interface is done by dragging, that is, it can be operated directly without having to write code to create the main window

2, the main window we can delete all the unwanted

3, then compile and run

we did not write a line of code, the MFC application runs up
4, drag a button from inside the toolbox into the main window

to modify elements

still did not write any code, compile and run again,

click the button and nothing happens, it is because there is no written message processing function
5, write a message handler
right to select class Wizard


Add handlers


After double-clicking, MFC framework we will locate here

the code to execute after the body of the function to write Click

date to just write a line of code, compile and run

the MFC framework inside, this message will click the button directly mapped to a class function go above

VII Summary:

GUI application development include:
the code used to create the program window and window elements.
In the message handler to respond differently according to a program message.

 

Guess you like

Origin www.cnblogs.com/luosir520/p/11619206.html