Application of controls in applications

zhaozj2021-02-11  212

Add controls in the window

A successful application is inseparable from a beautiful interface. This chapter mainly talks about the application of Windows built-in controls in applications, including how to declare variables and associate them with controls; how to keep synchronization between controls and variables; how to use control object IDs to retrieve control objects, thus Manipulate the control, and how to process the control as a window; how to specify the order in the application window in the application window, control the order of the application to switch the application in the window. I have never been written before, take this opportunity to exchange, communicate, it is inevitable that there is a mistake, please let you believe (Netvc@21cn.com) advice! Thank you!

Windows operating systems have multiple standard controls, including sliders, directory trees and list controls, progress bar, etc., this lecture is temporarily discussed several common controls, such as: Static Text (static text), Edit Box (edit box) , Command Button, Check Box, Radio Button, Drop-Down List Box (drop-down list box). These controls and other controls can be used in the Visual C application, which can be found in the control panel in the Dialog Painter editor in the VC development environment.

When adding controls to an application, you should follow the corresponding properties of the temple, such as ID and other visible properties, placement position, etc. When the position and attribute setting of all controls, the tabs of each control should be set as needed. You can choose one control first, select the layout | tab order command from the menu. After opening Tab ORDER, you can see a number next to each control. These numbers represent the order of switching in the dialog box, you can use the mouse with the mouse in the desired switching order, the control will be re-numbered in the specified order, specify the label order, then select Layout | Tab ORDER, return to the layout editor .

Help Miss: Help Missing is a button, check box, menu, etc. Title or other control tags in other control tags. The user can press the character and the Alt key at the same time, switch directly to the corresponding control or the event that is clicked in the control. To set a help message, you can add symbols to the character used as the help logger when setting the value of the title. The assistance in the same window or menu group can only be used once, so it should be checked whether the assistance has a conflict before touching the application code details. You can select the opposition box window or a control in the layout editor, click the right mouse button, select Check Mnemonics, if the help log is not conflict, Visual C will return a message dialog, display does not have conflicts, If there is a conflict, the dialog box indicates the conflict letter and displays the options for automatically picking the controls containing conflict assistance.

Associate controls with variables

Before starting the encoding, except for static text and commands, you must specify a variable to each control and add a value. You will interact with these variables when you write code for your application. The value in the user input screen control will give these variables, which will be used in the application code. At the same time, any value that the application gives these variables will be updated in the window control you see in the user. How do I declare these variables and associate them with controls in the window? We can provide Class Wizard tools with VC, select the Reverse Member Variables tab in Class Wizard, as shown below:

Select a ID that needs to be associated with the variable, click the Add Variable button, enter the variable name in the Add Variable dialog, specify the category, and the Variable Type, click the OK button. When entering a variable name, you should follow the MFC naming agreement, follow the naming agreement to make other programmers to read your program code; understanding that the naming agreement also makes you read the code compiled by other programming people. Associate functions and controls

After setting the location, attribute, option order, and variables of all controls, how should the function associated with the control? For example, how to retrieve the control object to be operated, manipulate the control, how to keep synchronization between the values ​​of the controls and variables, and how to process the control as a window. When you want to manipulate some controls, you should retrieve the control object first. In the VC, I can use the getDlgitem () function to retrieve the control object, such as getDlgitem (idc_msg) -> enableWindow (TRUE); its parameter IDC_MSG is the ID of the control Value, refers to the ID of the control to operate, the control of the control is to call EnableeIndow () so that it is available. The second call function enableWindow seems to be used in the window, not the control. This is true; but they happen to be members of the CWnd class, and the CWnd class is a ancestral class of the CDIALOG class. The CDAY2DLG class (the sample program's dialog class) is inherited by the CDIALOG class. In Windows, all the control year itself is a window, and is completely independent of their window. In this way, the control can be processed like a processing window and call the window function therein. In fact, all control classes are inherited from the CWND class, which means that the essence of the control class is the window. The most important thing in the application is that the values ​​of the controls and variables are synchronized, and we can use the Updatedata function. The Updatedata function is a key function for handling the annual variable in Visual C . The variable value is obtained by this function and updated the control on the screen with these variable values. It also gets data from the control and gives the user to the deduction value. This process is controlled by the parameter passed to the Updatedata function. If the parameter value is False, the variable value will be passed to the window control. If the parameter value is true, the variable will be updated with the value that appears in the window in the window. This is transmitted to the function depending on the direction that needs to be updated. After more than one variable in the code is updated, the letter Updatedata must be called to pass the value of the value of false. If you need to view the variable to get its current value, you need to call the Updatedata function before the value True must be used prior to view variables. This function should be hang when you need to add more code to your application.

Summary (Personal view):

Any application is programmed by controls and user input, output, and is familiar with the control of all aspects of the control. It is the basis for complex programming. In addition to the above introduction controls, VC also provides a lot of controls for users, can't be used here One detailed. An example program included in this chapter applies the contents of this chapter, and the specific function is described with reference to the instructions.

Download sample program

转载请注明原文地址:https://www.9cbs.com/read-3816.html

New Post(0)