MFC Button Does Not Click

Bryan Kelly 426 Reputation points
2025-04-22T19:39:39.02+00:00

Windows 11, Visual Studio 17.13.3, C++, MFC, dialog app

Question:  The most simple possible button does not work.  How could I have messed up Visual Studio to cause this?

Details:

I am trying to create an MFC project with dialogs.  The first set of buttons did work for a few iterations, I think, then stopped.  Now the most simple button will not work.

Create a new project as MFC App with C++.  I named this one MFC_Button. For application type select Dialog Based.  In User Interface Features add Minimize and Maximize boxes.  In Advanced Features Options disable ActiveX controls.  In Generated Classes options field “Generated classes” the options are App and Dlg.  As a guess Dlg is selected. (Edit, tried App, the only other option, same result)  Finish.

The project is created and the dialog is displayed.  From Toolbox drag a button into the dialog.  I named it Show.  Right click the button and select Add Event Handler.  Click OK accepting all the defaults.  The following code is presented with one line I added.

void CAboutDlg::OnBnClickedButton1()

{

            ``// TODO: Add your control notification handler code here

            ``int x = 1;

}

Put a breakpoint on the line int x = 1;  Build, run in debug, and wait a few seconds for VS to stabilize, then click the Show button.

The expectation is that the breakpoint will be hit.  It does not work.  What might I have done to mess up VS and cause this?

Tried several options.  Maybe that line is optimized out.  Go to class CAboutDlg and under “public:”  add:  int x.  In the constructor add: x = 0;  Change the button handler to:  x = 1;  Debug and click the button, no response.  And yes, the round red circle in the debug column is present next to: x = 1;  Just in case it is line 165.

What have I done to VS?  How might I fix it?

Visual Studio Debugging
Visual Studio Debugging
Visual Studio: A family of Microsoft suites of integrated development tools for building applications for Windows, the web and mobile devices.Debugging: The act or process of detecting, locating, and correcting logical or syntactical errors in a program or malfunctions in hardware. In hardware contexts, the term troubleshoot is the term more frequently used, especially if the problem is major.
1,066 questions
0 comments No comments
{count} votes

Accepted answer
  1. Viorel 121.3K Reputation points
    2025-04-22T19:49:13.09+00:00

    In Add Event Handler dialog, select your dialog instead of CAboutDlg.

    Or double-click the new button in Dialog Designer.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.