I am an MFC novice so hopefully someone will know the answer to this question. For some reason I cannot get buttons to work when they are located on a dialog which is used as a content holder for a tab. Specifically here is what I did.

Using Visual C++ in Visual Studio 2008, I created an MFC dialog-based application. In the resource editor, I added a tab control (IDC_MAIN_TABS) to the main dialog box.

I then created a class called TabsMain, inheriting from CTabCtrl. In the main dialog’s *.h file, I put an object of this type using the statement:

This creates one tab called “Image”. The TabsMainDlg.Init function will install a dialog as its content. So…

Again in the resource editor, I created a dialog resource (IDD_DLG_TAB_IMG) and indicated style = “child”. I put a button on that dialog (IDC_BTN_SAVE). I created a class for this dialog, called Dlg_TabImage inheriting from CDialog.

I then added an object of this class to the TabsMain.h file,

Dlg_TabImage DlgImageTab;

Then, in the TabsMain.cpp file, I added these lines to the TabsMain::Init() method:

I then went back to the resource editor, and right-clicked the button that was put on the dialog Dlg_TabImage. I create an event handler for when the button is pushed. The event handler simply puts up a message box saying the button was clicked.

However this doesn’t work. I can put a button and event handler on the main dialog using the same steps, and it works fine. But the one on the dialog which provides content for the tab doesn’t work. What am I missing?

Thanks

01-18-2010

novacain

Did you try setting the TAB to have the 'Image' tab selected (and so the small dlg active)?

Otherwise the main dlg may not be passing on the mouse click.

01-19-2010

ThunderChicken

I had not done that, so I added this statement in the OnInitDialog method of the main dialog box, after setting up the tabs:

Code:

TabsMainDlg.SetCurSel(0);

I believe this should select the one and only tab. However this did not make any difference. I set a breakpoint at the event handler of the button on the tab dialog, and run the program. The button appears to be pushed but the breakpoint never breaks.

01-19-2010

ThunderChicken

I totally apologize - I realized what is wrong and of course, it is a stupid mistake. I did not have the event handler associated with the button in question, it was associated with a non-existent button.

Now the question is, how do I remove my entire post so nobody will waste their time reading it?