2
votes

Suppose that I define a dialog called MyDialog which inherits from CDialog

MyDialog has a CEditBox which is defined in resource as following

EDITTEXT        IDC_AMOUNT,40,127,35,14
PUSHBUTTON      "OK",IDOK,51,193,50,14

Here is MyDialog's DoDataExchange

void MyDialog::DoDataExchange(CDataExchange* pDX)
{
   DDX_Text(pDX, IDC_AMOUNT, amount);
}

amount is a variable of type double. I understand that if I input a value which is not a double to IDC_AMOUNT control and press OK, MFC show the message box with the following message

Please enter a number

But I wonder if I hide the CEditBox with the following statements:

CWnd* pWnd=GetDlgItem(IDC_AMOUNT);
ASSERT(pWnd);
pWnd->ShowWindow(FALSE);

then after that when I press OK does MFC perform validation agains IDC_AMOUNT. In other words, does MFC perform validation agains hidden controls?

1

1 Answers

4
votes

The MFC just validates all controls that call a DDX routine in DoDataExchange.

The DDX routines never check if a control is enabled, or hidden.

If you want to do a data exchange only if the control is visible change your code. You can also check if you are in a loading or saving phase

void MyDialog::DoDataExchange(CDataExchange* pDX)
{
   // Only if saving and visible
   if (pDX->m_bSaveAndValidate && GetDlgItem(IDC_AMOUNT)->IsWindowVisible())
       DDX_Text(pDX, IDC_AMOUNT, amount);
}