It's very easy. I'm not sure it's the best solution but if you do the following and you'll reach the target:
- create a new dialog resource in ResourceView, it's supposed to be IDD_DIALOGBAR
- insert a new MFC class that derives from CWnd (choose "generic CWnd" as the base class) and it's supposed to be CMyDialogBar
- change the base class of CMyDialogBar from CWnd to CDialogBar
- add a button (IDC_BUTTON1) and a textbox (IDC_EDIT1) into your IDD_DIALOGBAR dialog resource
- define the message map for CMyDialogBar class by adding this macro:
BEGIN_MESSAGE_MAP(CFindBar, CWnd)
//{{AFX_MSG_MAP(CFindBar)
//}}AFX_MSG_MAP
ON_COMMAND(IDC_BUTTON1, OnButton1)
END_MESSAGE_MAP()
- add a new member function to CMyDialogBar with this prototype "afx_msg void OnButton1();" (it's not necessary to use afx_msg keyword in function implementation)
- put this code into your function implementation:
CEdit* pEdit = (CEdit*) GetDlgItem(IDC_STEXT_EDIT);
if (pEdit)
{
CString strText;
pEdit->GetWindowText(strText);
AfxMessageBox(strText);
}
- just run the application, click the button and see how it works.
Cheers,
Long.