I found following code in VS2015 MFC project.
#ifdef AFX_DESIGN_TIME
enum { IDD = IDD_DIALOG1 };
#endif
I would like to understand the purpose of this preprocessor. Google didn't give me anything sufficient. I will appreciate if you can shed some light on it.
Apparently it is used by the class wizard to map the dialog ID (IDD_DIALOG1
in your case) to the dialog class (derived from CDialoxEx).
If you remove the whole #ifdef AFX_DESIGN_TIME / #endif
section, the program will still compile fine, but the class wizard won't work properly anymore.
In older versions of Visual Studio, the constructor of a dialog class looked like this:
CSomeDlg::CSomeDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSomeDlg::IDD, pParent)
So the CSomeDlg::IDD
symbol was actually used during the compilation and there was no #ifdef AFX_DESIGN_TIME
.
In recent versions of Visual Studio (at least with VS2017) the constructor of a dialog class looks like this:
CSomeDlg::CSomeDlg(CWnd* pParent /*=NULL*/)
: CDialog(IDD_DIALOG1, pParent)
So the CSomeDlg::IDD
is no more useful during compilation and therefore Microsoft decided to compile it conditionally. But this is not strictly necessary, you could remove the #ifdef AFX_DESIGN_TIME
and the corresponding #endif
altogether, the code would still compile and the class wizard would still work correctly.
BTW, try to replace enum { IDD = IDD_DIALOG1 };
by enum { IDD = IDD_DIALOG123 };
and invoke the class wizard, you will get this error message:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With