0

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?

Barmak Shemirani
  • 30,904
  • 6
  • 40
  • 77
Archont
  • 101
  • 1
  • 9
  • 5
    `nIDC` is used to identify the control, so it has to be unique in the dialog, but it does not have to be globally unique (across different dialogs). Or what do you mean by unique? – Karsten Koop Dec 15 '16 at 08:04
  • @KarstenKoop you just answered my question :) thanks. – Archont Dec 15 '16 at 08:05
  • 2
    Control IDs must be unique for those controls only, that **your** code needs to identify by ID. This is the case for controls that participate in MFC's data exchange infrastructure, for example. Another example are button controls, where the ID is passed as part of the `WM_COMMAND` message, that buttons generate. Nothing keeps you from identifying controls by window handle, though, or not identifying controls at all (a static control is a well-known example for the latter kind, and they usually have the same `IDC_STATIC` assigned). – IInspectable Dec 15 '16 at 17:17
  • 2
    The scope for uniqueness is usually per window/dialog procedure, which roughly translates to *"per dialog"*. – IInspectable Dec 15 '16 at 17:19

1 Answers1

0

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 );
RonTLV
  • 2,376
  • 2
  • 24
  • 38