Click here to Skip to main content
15,901,205 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CAnimateCtrl crashes when going out of scope Pin
Cedric Moonen31-Aug-06 3:54
Cedric Moonen31-Aug-06 3:54 
GeneralRe: CAnimateCtrl crashes when going out of scope Pin
almc31-Aug-06 3:59
almc31-Aug-06 3:59 
GeneralRe: CAnimateCtrl crashes when going out of scope Pin
David Crow31-Aug-06 7:34
David Crow31-Aug-06 7:34 
GeneralRe: CAnimateCtrl crashes when going out of scope Pin
almc31-Aug-06 23:05
almc31-Aug-06 23:05 
QuestionBackGround Bitmap Pin
radhika2831-Aug-06 3:45
radhika2831-Aug-06 3:45 
AnswerRe: BackGround Bitmap Pin
_AnsHUMAN_ 31-Aug-06 4:03
_AnsHUMAN_ 31-Aug-06 4:03 
AnswerRe: BackGround Bitmap Pin
Hamid_RT31-Aug-06 7:31
Hamid_RT31-Aug-06 7:31 
QuestionQuestion for Foreign Langauge Speakers Pin
Joel Holdsworth31-Aug-06 3:36
Joel Holdsworth31-Aug-06 3:36 
AnswerRe: Question for Foreign Langauge Speakers Pin
toxcct31-Aug-06 3:44
toxcct31-Aug-06 3:44 
AnswerRe: Question for Foreign Langauge Speakers Pin
Rage31-Aug-06 3:45
professionalRage31-Aug-06 3:45 
GeneralRe: Question for Foreign Langauge Speakers Pin
toxcct31-Aug-06 4:09
toxcct31-Aug-06 4:09 
Questionshow text on next line in an edit box Pin
Kiran Pinjala31-Aug-06 2:44
Kiran Pinjala31-Aug-06 2:44 
AnswerRe: show text on next line in an edit box Pin
_AnsHUMAN_ 31-Aug-06 2:51
_AnsHUMAN_ 31-Aug-06 2:51 
QuestionMouse button down Pin
majco33331-Aug-06 2:14
majco33331-Aug-06 2:14 
AnswerRe: Mouse button down Pin
toxcct31-Aug-06 2:26
toxcct31-Aug-06 2:26 
AnswerRe: Mouse button down Pin
IlanTal31-Aug-06 2:26
IlanTal31-Aug-06 2:26 
AnswerRe: Mouse button down Pin
_AnsHUMAN_ 31-Aug-06 2:41
_AnsHUMAN_ 31-Aug-06 2:41 
GeneralRe: Mouse button down Pin
majco33331-Aug-06 2:35
majco33331-Aug-06 2:35 
GeneralRe: Mouse button down Pin
_AnsHUMAN_ 31-Aug-06 3:22
_AnsHUMAN_ 31-Aug-06 3:22 
GeneralRe: Mouse button down Pin
majco33331-Aug-06 3:25
majco33331-Aug-06 3:25 
QuestionHow do I write red text to a CDialogBar? Pin
IlanTal31-Aug-06 1:39
IlanTal31-Aug-06 1:39 
AnswerRe: How do I write red text to a CDialogBar? Pin
ovidiucucu31-Aug-06 6:16
ovidiucucu31-Aug-06 6:16 
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)->GetSafeHwnd())
   {
      pDC->SetTextColor(RGB(255,0,0)); // set red text color
      hbr = (HBRUSH)::GetStockObject(WHITE_BRUSH); // return valid brush handle
   }
   return hbr;
}


Ovidiu Cucu
Microsoft MVP - Visual C++

GeneralRe: How do I write red text to a CDialogBar? Pin
IlanTal3-Sep-06 21:44
IlanTal3-Sep-06 21:44 
GeneralRe: How do I write red text to a CDialogBar? Pin
ovidiucucu4-Sep-06 0:04
ovidiucucu4-Sep-06 0:04 
GeneralRe: How do I write red text to a CDialogBar? Pin
IlanTal4-Sep-06 20:19
IlanTal4-Sep-06 20:19 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.