Button within a dialog in a CTabCtrl don't work?

Posted on 2003-03-19
Medium Priority
Last Modified: 2013-11-20
Hi all
I'm relatively new to MFC coding, so I hope you can help.
My problem is:
I have a dialog. Within this dialog is a CTabCtrl. This CTabCtrl has a dialog with it's own class. Within this dialog contains a button. Clicking on the button should bring up a AfxMessageBox("Test") but doesn't bring up anything. I tried setting a breakpoint on this line and it's never reached...

To reproduce the problem, do the following:
 - Create a new Dialog Based MFC AppWizard Project (I called it "Tester")
 - On the IDD_TESTER_DIALOG, place a CTabCtrl with the default name "IDC_TAB1"
 - In the Classwizard, for IDC_TAB1, Add a variable. Call it "m_Tabs" with Category "Control" and type "CTabCtrl"
 - Insert a new dialog with default name "IDD_DIALOG1", style="Child" and no title bar.
 - In "TesterDlg.h", go to the definition of m_Tabs. Under this line, put "CDialog   m_TestDlg" so it becomes:

     enum { IDD = IDD_TESTER_DIALOG };
     CTabCtrl     m_Tabs;
     CDialog     m_TestDlg;

 - In "TesterDlg.cpp", in the CTesterDlg::OnInitDialog() section, add the following under the SetIcon lines:

     m_Tabs.InsertItem (0, "Test");
     m_TestDlg.Create (IDD_DIALOG1, &m_Tabs);
     m_TestDlg.ShowWindow (SW_SHOW);

 - Go to IDD_DIALOG1. Place a button with a default name of "IDC_BUTTON1"
 - Double click on the button. It will ask you to create a class. Create a new class named "CTheTester" with a Base Class "CDialog" and DialogID "IDD_DIALOG1".
 - Exit the Classwizard if you're still there
 - Double click on the button again. This time it will ask you to name the member function. Call it "OnButton1"
 - Within this function, put the line "AfxMessageBox ("Test!");"
 - Compile and run.

When you click the button we created, it doesn't work...Can anyone tell me where I went wrong? or if there's any lines I should add to rectify this?

The same thing happens when I put down a combo box and test to see when the contents change, so I think it may happen for any controls I put down.

Thanks for any help!
Question by:Amigaboy
LVL 48

Accepted Solution

AlexFM earned 200 total points
ID: 8172118
Two corrections in TesterDlg.h:

// CTesterDlg dialog

#include "TheTester.h"     // !! add this line

class CTesterDlg : public CDialog
// Construction
    CTesterDlg(CWnd* pParent = NULL);     // standard constructor

// Dialog Data
    enum { IDD = IDD_TESTER_DIALOG };
    CTabCtrl     m_Tabs;
    CTheTester     m_TestDlg;  // !! changed from CDialog

Author Comment

ID: 8172188
D'oh! I forgot to add the include. That was an obvious mistake by me. The CTheTester thing I would have never figured out.
It all worked great.
Thanks for your help! :)

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question