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:
TabsMain TabsMainDlg;
In the main dialog’s *.cpp file, in the DoDataExchange method, I put:
DDX_Control(pDX, IDC_MAIN_TABS, TabsMainDlg);
And in the OnInitDialog method, I added the following statements:
Code:
TabsMainDlg.InsertItem(0, _T("Image"));
TabsMainDlg.Init();
TabsMainDlg.ShowWindow(SW_SHOW);
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:
Code:
DlgImageTab.Create(IDD_DLG_TAB_IMG, this);
DlgImageTab.ShowWindow(SW_SHOW);
At this point the dialog (with the button) shows up in the tab.
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.
So now in Dlg_TabImage.cpp there is a handler method:
Code:
void Dlg_TabImage::OnBnClickedBtnCapture()
{
CString msg;
msg.Format(_T("This button doesn't work"));
AfxMessageBox(msg);
}
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