|
Question : Change the background color of a CDateTimeCtrl object.
|
|
Ok... I have a CDateTimeCtrl object in my MFC based Dialog, it is of the spin control variety (not the drop down calendar). The question is, how can I change the color of the edit box's background and the color of the text?
|
|
Answer : Change the background color of a CDateTimeCtrl object.
|
|
hI here is working(i.e.tested code ) try this //////////////////////////////////// //MyDTP.h file
class CMyDTP : public CDateTimeCtrl { public: CMyDTP(){}; virtual ~CMyDTP(){};
protected: afx_msg BOOL OnEraseBkgnd(CDC* pDC); DECLARE_MESSAGE_MAP() };
//////////////////////////////////// //MyDTP.cpp file
BEGIN_MESSAGE_MAP(CMyDTP, CDateTimeCtrl) ON_WM_ERASEBKGND() END_MESSAGE_MAP()
BOOL CMyDTP::OnEraseBkgnd(CDC* pDC) { BOOL ret = CDateTimeCtrl::OnEraseBkgnd(pDC); CRect rct; GetClientRect(&rct); pDC->FillSolidRect (&rct,RGB(192,0,192)); return ret; }
in dialogbox where you want to put that DateTime control I have created in OnInitDialog like this ( you can create it anywhere)
m_pMyDTP = new CMyDTP ();// CMyDTP *m_pMyDTP is class member of dialog CRect rect(20, 20, 120, 45); ASSERT(m_pMyDTP->Create(WS_VISIBLE | WS_CHILD | WS_TABSTOP | DTS_UPDOWN|DTS_SHOWNONE | DTS_SHORTDATEFORMAT, rect, this, 1006)!= NULL);
//I have choosen ctrlid = 1006 arbitrarily if this conflict with any other control // please select any other id. As this is working fine in my code I hope it will work with your app too if you find any problem please let me know.
Good Luck
|
|
|
|