Link to home
Start Free TrialLog in
Avatar of Amigaboy
Amigaboy

asked on

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

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:

     //{{AFX_DATA(CTesterDlg)
     enum { IDD = IDD_TESTER_DIALOG };
     CTabCtrl     m_Tabs;
     CDialog     m_TestDlg;
     //}}AFX_DATA

 - 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!
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Amigaboy
Amigaboy

ASKER

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! :)