Assume that there is a Dialog: MyDialog to dynamically create a set of buttons as an example. 1. Add declarations in MyDialog.h: protected: cbutton m_btnwork [5]; // Generate 5 buttons
2. Add: #define IDC_Button_Work 2005 in MyDialog.cpp
3. Add: create button in MyDialog.cpp: CRECT RECT; // button Location and size Rect.Lect = 20; Rect.Right = Rect.Left 100; Rect.top = 20; Rect.Bottom = Rect .top 20;
For (int i = 0; i <5; i ) {
/ / Make sure the button will not coincide with RECT.TOP = 30; Rect.Bottom = 30;
// Dynamically create button m_bTnwork [i] .createex (null, _t ("" button)), // Description is to generate button, depending on the generated thing, to make the corresponding change null, ws_child, rect, this, id_mybtn i ); // Generate an edit control
// Set the CAPTION CSTRING text; Text.Format ("Button% D", I); setdlgitemtext (IDC_Button_Work i, Text); // Display control M_BTnWork [i] .showwindow;}
If you want to join a message mapping, you want: 1. Add: AFX_MSG void OnmyButtonClicked ();
2. Add: on_bn_clicked (idc_button_work, onmybuttonclicked) between MyDialog.cpp (CDYNAMICCREATEDLG, CDIALOG)
3. Add: void cmydialog :: onmybuttonclicked () {// Todo: Add Your Control Notification Handler Code Here MessageBox ("Hello");}