Click here to Skip to main content
15,893,368 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
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 
GeneralRe: How do I write red text to a CDialogBar? Pin
IlanTal4-Sep-06 23:06
IlanTal4-Sep-06 23:06 
Question(*pf)(int); *pf(int); Pin
Max++31-Aug-06 1:21
Max++31-Aug-06 1:21 
AnswerRe: (*pf)(int); *pf(int); Pin
salman kazi31-Aug-06 1:40
salman kazi31-Aug-06 1:40 
AnswerRe: (*pf)(int); *pf(int); Pin
toxcct31-Aug-06 1:56
toxcct31-Aug-06 1:56 
Questionhow i block the e-mail attachment in VC++? Pin
salman kazi31-Aug-06 1:19
salman kazi31-Aug-06 1:19 
QuestionWindows date and time conversion Pin
ashokvishnu31-Aug-06 0:57
ashokvishnu31-Aug-06 0:57 
AnswerRe: Windows date and time conversion Pin
_AnsHUMAN_ 31-Aug-06 1:01
_AnsHUMAN_ 31-Aug-06 1:01 
AnswerRe: View Refresh problem Pin
Cedric Moonen31-Aug-06 0:52
Cedric Moonen31-Aug-06 0:52 
QuestionCGRAPH OR MS CHART?? Pin
weehau31-Aug-06 0:20
weehau31-Aug-06 0:20 
AnswerRe: CGRAPH OR MS CHART?? Pin
toxcct31-Aug-06 0:40
toxcct31-Aug-06 0:40 
GeneralRe: CGRAPH OR MS CHART?? Pin
Cedric Moonen31-Aug-06 0:51
Cedric Moonen31-Aug-06 0:51 
GeneralRe: CGRAPH OR MS CHART?? Pin
toxcct31-Aug-06 0:51
toxcct31-Aug-06 0:51 
GeneralRe: CGRAPH OR MS CHART?? Pin
dinesh_IP31-Aug-06 1:50
dinesh_IP31-Aug-06 1:50 
GeneralRe: CGRAPH OR MS CHART?? Pin
toxcct31-Aug-06 1:57
toxcct31-Aug-06 1:57 

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.