Building MFC Dialogs at Run Time
by Adrian Hill

Example 1:

int    exposure_time_ms = 8;  // Two different numeric types.
double laser_power_mw = 40.0;

Dynamic_dialog dlg("Camera Image Capture", 155, 100);

dlg.Add_OK_button(20, 70, 50, 14);
dlg.Add_Cancel_button(85, 70, 50, 14);
dlg.Add_edit_control("Exposure time", 15, "ms.", 70, 20,
                     45, 12, &exposure_time_ms, 1, 100);
dlg.Add_edit_control("Laser power",   15, "mW.", 70, 40,
                     45, 12, &laser_power_mw, 0.1, 200.0);
if (dlg.DoModal() == IDOK)
   {
   // ... more code ...



Example 2:

// ----- Message Map -----
BEGIN_MESSAGE_MAP(Dynamic_dialog, CDialog)
   ON_BN_CLICKED(Dynamic_dialog::e_first_browse_idc,     OnBrowse0)
   ON_BN_CLICKED(Dynamic_dialog::e_first_browse_idc + 1, OnBrowse1)
   ON_BN_CLICKED(Dynamic_dialog::e_first_browse_idc + 2, OnBrowse2)
   ON_BN_CLICKED(Dynamic_dialog::e_first_browse_idc + 3, OnBrowse3)
END_MESSAGE_MAP()

void Browse(int button);

// ----- OnBrowse? functions ----
void Dynamic_dialog::OnBrowse0() { Browse(0); }
void Dynamic_dialog::OnBrowse1() { Browse(1); }
void Dynamic_dialog::OnBrowse2() { Browse(2); }
void Dynamic_dialog::OnBrowse3() { Browse(3); }





1


