There are also many questions about the dynamic creation dialog box on the Internet.ArticleBut most of them are similar.
The key is:
See the following two different dynamic creation dialog boxes.
1. cdialog DLG;
DLG. Create (idd_dialog );
Dig. showwindow (sw_show );
2. cdialog * DLG = new cdialog;
DLG-> Create (idd_dialog );
DLG-> showwindow (sw_showwindow );
1. The dynamic creation dialog box cannot be displayed, and 2 the dynamic creation dialog box can be displayed.
Why is this happening? The answer is actually very simple.
Because cdialog DLG in 1 is a defined local object, within the scope of its function module, as the function is executed, local objects will disappear. Therefore, we need to apply for a memory area in step 2, but remember to release the memory area in the destructor of the dialog box class to avoid Memory leakage.
The principle for dynamically creating controls is the same here.