http://www.codeproject.com/KB/dialog/dialogsubclass.aspx.
But it seems to me that your way is exactly as same as I worte below.
See my essay on subclassing dialogs. There's no reason to create the
button at runtime,
by the way, and certainly not with nonsensical values like 1,1,100,30 (I
don't know how
many times I have to explain this: those numbers are completely
meaningless, and only work
on your computer today; they won't produce the same results tomorrow, if
you have changed
any of a number of parameters of your machine, such as the default font,
the screen
resolution, the screen size, the graphics card, the display driver, etc.).
Often what I
do is simply create the button with the same ID at design time; other
times, I will embed
another dialog with a set of controls (I should write an essay on this).
I cover all your questions in my essay on my MVP Tips site. Search for
"subclassing
dialogs"
joe
I have many dialog boxes which have a same feature: All of these dialogs
have a button named "setting information". To avoid handling these buttons
one by one, I make a CBaseDlg based on CDialog as follows,
class CBaseDlg : public CDialog
{
public:
CBaseDlg(UINT ID, CWnd* pParent = NULL);
protected:
virtual void DoDataExchange(CDataExchange* pDX);
protected:
CButton m_btn;
virtual BOOL OnInitDialog();
afx_msg void OnBtnSettingInf();
}
BEGIN_MESSAGE_MAP(CBaseDlg, CDialog)
ON_BN_CLICKED(IDC_BTNSETTINGINF, OnBtnSettingInf)
END_MESSAGE_MAP()
BOOL CBaseDlg::OnInitDialog()
{
CDialog::OnInitDialog();
m_btn.Create( "setting information",
WS_CHILD | WS_VISIBLE | BS_PUSHBUTTON | WS_TABSTOP,
CRect(1,1,100,30),
this,
IDC_BTNSETTINGINF);
return TRUE;
}
void CBaseDlg::OnBtnSettingInf()
{
CSettingInformation dlg;
dlg.DoModal();
}
If I use CBaseDlg to create a dialog(IDD = IDD_DIALOG1), the button is
showed on IDD_DIALOG1. But when I push the button,
CBaseDlg::OnBtnSettingInf() is not called.
How to make it work?
TIA
ou