CDialogBar event handlers trouble
-
Hi, first of all I do apologize if the question is already in the message board, but I cannot find it. Here's my problem. I've implemented a CDialogBar derived class (it makes common initializations to all the dialog bar I need); then I've derived from it a lot of classes each of which implements a specific dialog (created with the dialog designer); in one of them there are various controls (buttons, static text, list box, ecc.); when I add an event associated with a control (e.g. the OnClick event of a button) the designer creates the corresponding method in the class associated to the dialog. I run the program and the button is disabled. If I move the entry ON_BN_CLICKED of the CDialogBar derived class' message map into the MainFrm's one, the button is enable, but when the event is fired and the method is called the 'this' pointer within the method points to the MainFrm instance (I would like that the reference is the CDialogBar derived class). What's wrong? Thanks in advance for any response.
-
Hi, first of all I do apologize if the question is already in the message board, but I cannot find it. Here's my problem. I've implemented a CDialogBar derived class (it makes common initializations to all the dialog bar I need); then I've derived from it a lot of classes each of which implements a specific dialog (created with the dialog designer); in one of them there are various controls (buttons, static text, list box, ecc.); when I add an event associated with a control (e.g. the OnClick event of a button) the designer creates the corresponding method in the class associated to the dialog. I run the program and the button is disabled. If I move the entry ON_BN_CLICKED of the CDialogBar derived class' message map into the MainFrm's one, the button is enable, but when the event is fired and the method is called the 'this' pointer within the method points to the MainFrm instance (I would like that the reference is the CDialogBar derived class). What's wrong? Thanks in advance for any response.
Keep the event handler in the CDialogBar[-derived] class itself. To enable the button, you need to handle ON_UPDATE_COMMAND_UI like,
BEGIN_MESSAGE_MAP(CYourDialogBar, CDialogBar)
//{{AFX_MSG_MAP(CYourDialogBar)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateButton1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()void CYourDialogBar::OnUpdateButton1(CCmdUI *pCmdUI)
{
pCmdUI->Enable(TRUE);
}