MFC problem - getting buttons to work on tab dialogs
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:
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:
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,
Then, in the TabsMain.cpp file, I added these lines to the TabsMain::Init() method:
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:
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?
msg.Format(_T("This button doesn't work"));