c++windowsmfcddx

C++ - in DDX_Text function should a nIDC be unique?


Let's say we have some Dialog and in DoDataExchange function we have some DDX_Text calls which works with some text fields. Let's see a prototype:

void AFXAPI DDX_Text( CDataExchange* pDX, int nIDC, CString& value );

I'm new to Windows Dialogs and this Dynamic Data Exchange Mechanic and i haven't found answer fast enough. Something tells me that nIDC should be unique value, but in fact in real project i see that this is not always true.

So the question is: When can we have nIDC a unique and when not? Should we or should not?


Solution

  • Clearly nIDC has to unique. You never want to be in a situation were you have two or more resources with the same value.

    I myself use DDX_Text fairly often outside DoDataExchange to read/write a control value. Example of reading from control to a value:

    UINT num;
    CDataExchange dx( this, TRUE );
    DDX_Text( &dx, IDC_EDIT1, num );