C++ MFC Button on a second Dialog does nothing

I created a C++ MFC Program with the Visual Studio Wizard. There I set the application type to "Dialog Based".

I have a button on the first dialog, which opens another dialog. I created this second dialog by right clicking on the project -> Add -> Resource -> Dialog -> New. Then I added a MFC class to the new dialog by double clicking it in resource view.

On the second Dialog I also created a button. I double clicked the button and added some code which should be executed.

When I run the program and click the button on the second dialog, nothing happens and the code is not executed. I did everything like with the button on the first dialog. That one works fine. Why is the second button not working and what do I need to do?

First Dialog

void CMFCApplication1Dlg::OnBnClickedButton1()
    CDialogEx secondDialog(IDD_DIALOG1);

Second Dialog

void SettingsDlg::OnBnClickedButton1()
    MessageBox(L"Button clicked", L"Button clicked", MB_OK);

Read more here: https://stackoverflow.com/questions/64891843/c-mfc-button-on-a-second-dialog-does-nothing

Content Attribution

This content was originally published by Ceph at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: