Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the purpose of AFX_DESIGN_TIME and where it is defined?

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.

like image 243
aks Avatar asked Apr 06 '18 02:04

aks


1 Answers

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:

enter image description here

like image 96
Jabberwocky Avatar answered Sep 20 '22 20:09

Jabberwocky