Listing 5
struct employee {
std::string first_name;
std::string last_name;
int id;
unsigned long salary;
// ... etc.
};
void valid_name(
const std::string & old_name, const std::string & new_name,
save_dlg::info<employee> & info) {
if (new_name.size() < 4)
info.error = "Name should contain at least four letters";
}
// ... somewhere in code
employee empl;
// ... fill empl structure
// create correspondence from controls to empl' data
save_dlg::corresp empl_corresp;
empl_corresp
// add the original value - the one that is
// modified when the dialog is closed
.add_var(empl)
// create correspondence from data to controls
.add_corresp( &employee::first_name, ID_first_name)
.add_corresp( &employee::last_name, ID_last_name)
.add_corresp( &employee::id, ID_id)
.add_corresp( &employee::phone, ID_phone)
// validate First & Last names
.add_validator(ID_first_name, &valid_name, validate::on_exit)
.add_validator(ID_last_name, &valid_name, validate::on_exit)
;
// show "Employee Summary" Dialog on the screen
create_save_dlg( IDD_empl_summary, empl_corresp);
// here, whatever user entered in the controls is saved into 'empl' structure