Thursday, January 26, 2017

MFC dialog properties do not display Control Events or Message properties

Problem: I was creating a new dialog in an old MFC project, and notified that the new dialog did not display any entry under the dialog properties' Control Events section or the Messages section. There was however no problem running the dialog - even capturing click events etc.. So the problem was annoying, but not much more.

Analysis: In dialogs where this displayed correctly, I noticed that the difference was in the constructor of the dialog class. My code had something like:
MyDlg::MyDlg() : CDialog(IDD_MY_DIALOG, nullptr)

Solution: Some of the working classes had:

MyDlg::MyDlg() : CDialog(IDDnullptr)

...where IDD was defined like this in the header file:

enum { IDD = IDD_MY_DIALOG };  

Solution: It turns out that the enum line in the header is needed to make Visual Studio connect the dots between the dialog and its dialog class. It is actually also being explained in this StackOverflow article.