In some problems you may want to collect less information from a dialog box than in others. When creating a new bank account you may or may not want to specify the method of interest dispersal. You may allow editing the dispersal field using a dialog activated by a button. An alternative is to only allow the user to see the dispersal field for the types of accounts that allow you to alter this value.
The dialog with all fields showing looks like this.
The dialog for an account in which you cannot set the dispersal is smaller.
Since the account type determines the amount of information gathered, we build enablers into the account class. The dialog receivers a pointer to an account and the SetupWindow function uses this function to determine the size of the dialog at run time. In addition to resizing the dialog, windows outside the visible portion of the dialog are disabled so the user won't tab off the visible area of the dialog. Here is that function.
void Accountdlg::SetupWindow ()
{
TDialog::SetupWindow();
// INSERT>> Your code here.
TRect dlgRect;
GetWindowRect(dlgRect);
int offSet;
if (_acct->interestDispersal())
offSet = 0;
else
{
offSet =70;
_dispersal->EnableWindow(FALSE);// won't tab outside visible window
}
MoveWindow(dlgRect.left,dlgRect.top,
dlgRect.Width(),dlgRect.Height() - offSet);
}
The rest of the code is just like the code in the original, except that now you can set all of the account's values from the account dialog transfer buffer.
For the complete code of this example click here