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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get MySQL database support online, now!

At Percona’s web store you can order your MySQL database support needs in minutes. No hassles, no fuss, just pick and click. Pay online with a credit card.

Question has a verified solution.

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

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…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month10 days, 10 hours left to enroll

765 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