Page 58 - DCAP408_WEB_PROGRAMMING
P. 58
Windows Programming
Notes
Example: Here is an example:
void CDialog5Dlg::OnLetItBe()
{
// TODO: Add your control notification handler code here
m_Submit.EnableWindow(FALSE);
}
4.5.4 The OK and Cancel Buttons
The most well-liked button captions in dialog boxes are OK and Cancel. The OK caption is set for
a dialog box that notifies the user of an error, a mediator situation, or an acknowledgement of
an action that was accomplished on the dialog that hosts the button. Microsoft Visual C++ makes
it simple to add an OK button since in Windows applications, the OK object has a particular
meaning.
To use an OK button, add a button to a form and, from the ID combo box, choose the
IDOKidentifier:
What makes this constant unique is that the MFC library identifies that, when the user clicks it,
if the dialog box is modal, the user is recognizing the situation. If this dialog box was called from
another window by means of the DoModal() member function, you can locate out if the user had
clicked OK and then you can take further action. Thus when the user clicks OK, the dialog box
calls the OnOK() member function. Its syntax is:
virtual void OnOK();
Even though it appears like a simple member function (and it is), the OnOK() member function
carries the constant value IDOK that you can utilize as a return value of the DoModal()member
function. Thus, in one step, you can utilize the DoModal() member function to exhibit a modal
dialog box and discover whether the user clicked OK.
When a dialog box is prepared with an OK button, you should permit the user to press Enter and
execute the OK clicking. This is taken care of by setting the Default Button property to True or
checked.
52 LOVELY PROFESSIONAL UNIVERSITY