mfc how to delete controls

Reference: https://blog.csdn.net/b2292486308/article/details/53695662

 

One: Manually delete

1. First determine what related variables and functions the control has; open the .rc2 file and delete the corresponding control icon in it;

2. Open the main dialog header file; (the functions and variable definitions generated by the general class wizard are in the last "public" l of the header file); find the generated variable definitions and function definitions and delete them;

3. Open the dialog source file, find the processing function defined by the control, and delete it (you can also double-click the control button at the beginning to find the defined function to delete)

4. In the BEGIN_MESSAGE_MAP () message mapping function, delete the message function corresponding to the control (generally there is a wavy mark)

5. Finally, delete the data exchange statement of the variable; in the void CTestDlg :: DoDataExchange (CDataExchange * pDX) function; the test here is a custom function.

Two: delete through the class wizard

1. Open the .rc file; find the control you want to delete; right-click after selecting the control; select "Class Wizard"; find the message and member variables corresponding to the control on the Class Wizard page, click "Delete Handler" after selecting; some controls No event function, you can delete directly, such as text

At this time, the definition declaration of variables in the source file, the relevant statements of the data exchange function, and the information in the message map are all annotated.

2. Delete the control in the dialog box.

The above deletion method solves the problem of automatically adding the place after adding the control, and sometimes it is the code that we actively write, which uses the control iD and other variables. This requires us to find out and delete it. Generally, an error will be reported during compilation. This is easy to handle and find the place where the error is reported. Sometimes it can't be checked during compilation, and an error is reported during runtime. This requires finding the location by setting a breakpoint.

Errors 2001 and 1120 are reported at compile time

      1 This compilation error will not indicate the location. This error may be due to the mfc message function not implemented.

Solution: Enter the class wizard, as shown below

 

When using the second method above, the member variables and functions will be deleted, and the messages that are easy to miss are messages.

The bold text in the Messages column is the added message. See if it is useless, such as WM_HSCROLL, which is a slider message. It is easy to miss this when deleting the slider. Or BEGIN_MESSAGE_MAP in the source file Dlg.cpp comment out unused message functions.

       2 Another reason for this error is that the library file is not configured correctly

Error when running

For example, to set whether other buttons can be pressed in a button, write the following lines of code, use the ID of these buttons, and delete these buttons, these few words are wrong. But no error is reported during compilation, and an error is reported during runtime. You can find the location by setting a breakpoint.

Published 59 original articles · Likes46 · Visits 30,000+

Guess you like

Origin blog.csdn.net/sinat_41852207/article/details/96044293