First of all, few aside notes:
- A dialog bar is not quite similar to a dialog box, although both can be based on a dialog template. That because CDialogBar is not derived from CDialog but from CControlBar.
- OnDraw is a virtual member function of CView which is called from within WM_PAINT message handler (OnPaint). Neither CDialog, nor CDialogBar have OnDraw method.
- If you need a text in a dialog box or a dialog bar is easier to put it in a static or edit control rather than drawing it in WM_PAINT message handler.
Given these said, I would like to suggest to derive from CDialogBar, make some "cosmetics", i.e. adding WM_INITDIALOG message handler (CDialogBar has not OnInitDialog virtual function like CDialog), change the edit's font in that handler, and finally set the edit's text color in WM_CTLCOLOR message handler. Here is a sample code:
// MyDialogBar.h
class CMyDialogBar : public CDialogBar
{
// Construction
public:
CMyDialogBar();
// ...
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CMyDialogBar)
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//}}AFX_MSG
afx_msg LRESULT OnInitDialog (WPARAM wParam, LPARAM lParam); // <-- added by hand
DECLARE_MESSAGE_MAP()
};
// MyDialogBar.cpp
// ...
MyDialogBar::CMyDialogBar()
{
// ...
}
void CMyDialogBar::DoDataExchange(CDataExchange* pDX)
{
CDialogBar::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDialogBar)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDialogBar, CDialogBar)
//{{AFX_MSG_MAP(CMyDialogBar)
ON_WM_CTLCOLOR()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_INITDIALOG, OnInitDialog) // <-- added by hand
END_MESSAGE_MAP()
LRESULT CMyDialogBar::OnInitDialog (WPARAM wParam, LPARAM lParam)
{
if (!HandleInitDialog(wParam, lParam) || !UpdateData(FALSE))
{
TRACE0("Warning: UpdateData failed during dialog init.\n");
return (LRESULT)0;
}
CFont font;
font.CreatePointFont(140, _T("Times New Roman"));
CWnd* pEdit = GetDlgItem(IDC_EDIT_PATIENT);
_ASSERTE(NULL != pEdit); // something stinks in here!
pEdit->SetFont(&font); // set the "larger" font
font.Detach();
return (LRESULT)1;
}
HBRUSH CMyDialogBar::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialogBar::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd->m_hWnd == GetDlgItem(IDC_EDIT_PATIENT)->GetSafeHwn