I have a CEdit field in my dialog where I have implemented EN_KILLFOCUS
, so when the user enters invalid data a warning message is displayed when the focus moves away from this field and the focus returns to the CEdit field so that the user can enter proper data. If the user enters invalid data and clicks on the CANCEL button, then also a warning message is displayed which is undesirable because the user is anyway trying to cancel his actions. I have tried implementing PostQuitMessage when the user clicks on CANCEL button, but this closes the entire application. I want only my dialog to close when the user clicks CANCEL button. Is there any way that I can close the dialog instantly after I click on CANCEL button. This is the code that I tried.
void CMARPropWnd::OnParentNotify(UINT message, LPARAM lParam)
{
CCDialog::OnParentNotify(message, lParam);
// TODO: Add your message handler code here
CPoint ptButtonDown(LOWORD(lParam),HIWORD(lParam));
if ((message == WM_LBUTTONDOWN) && (ChildWindowFromPoint(ptButtonDown) == GetDlgItem(eMARPropWndCancelBtnId)))
{
PostQuitMessage(0);
}
}
Try
instead of PostQuitMessage(0);
Note that OnCancel() is a virtual method of CDialog, so this is the "most correct", and will do any special code that may override the default CDialog behavior.