|
-
August 22nd, 2001, 10:17 AM
#1
CDateTimeCtrl - background color
Hi!
Who know how change background color of CDateTimeCtrl (in edit-part of control)?
Thanks!
-
October 1st, 2001, 07:24 AM
#2
Re: CDateTimeCtrl - background color
Create a new class CMyDateTimeCtrl deriving it from CDateTimeCtrl using class wizard and add a handler for the WM_ERASEBKGND message
Add the following to the .h file:
Code:
COLORREF SetBackgroundColor(BOOL bSysColor, COLORREF cr);
COLORREF m_bkgd_color;
CBrush* m_bkgd_brush;
Add this to the .cpp file:
Code:
COLORREF CMyDateTimeCtrl::SetBackgroundColor(BOOL bSysColor, COLORREF cr)
{
COLORREF ret_color = m_bkgd_color; // return old color
m_bkgd_color = bSysColor ? ::GetSysColor(COLOR_WINDOW) : cr;
if (ret_color != m_bkgd_color) // color changed?
{
delete m_bkgd_brush; // throw away old brush
m_bkgd_brush = new CBrush(m_bkgd_color); // buy a new one ;-)
Invalidate(); // repaint
}
return ret_color;
}
BOOL CMyDateTimeCtrl::OnEraseBkgnd(CDC* pDC)
{
CBrush * old_brush = pDC->SelectObject(m_bkgd_brush);
CRect rect;
pDC->GetClipBox(&rect);
pDC->PatBlt(rect.left, rect.top, rect.Width(), rect.Height(), PATCOPY);
pDC->SelectObject(old_brush);
return TRUE;
}
Your constructor and destructor should be changed to this:
Code:
CMyDateTimeCtrl::CMyDateTimeCtrl()
: CDateTimeCtrl(), m_bkgd_color(::GetSysColor(COLOR_WINDOW))
{
m_bkgd_brush = new CBrush(::GetSysColor(COLOR_WINDOW));
}
CMyDateTimeCtrl::~CMyDateTimeCtrl()
{
delete m_bkgd_brush;
}
HTH
Jens C.
Last edited by JensC; April 29th, 2009 at 06:35 AM.
-
October 1st, 2001, 07:29 AM
#3
Re: CDateTimeCtrl - background color
Oops, I did it again!! The call to Invalidate() does not belong to the comment. Please insert CR/LF in front of it. Sorry for the GBF (General Brain Failure).
Jens C.
-
October 1st, 2001, 10:56 AM
#4
Re: CDateTimeCtrl - background color
And another one... Please replace COLOR_BACKGROUND by COLOR_WINDOW. Sorry again.
Live long and prosper
JensC
-
April 29th, 2009, 06:11 AM
#5
Re: CDateTimeCtrl - background color
And also add BOOL OnEraseBkgnd(CDC* pDC); to the header file too 
And replace those HTML > codes with > symbol 
error C2084: function '__thiscall CMyDateTimeCtrl::~ CMyDateTimeCtrl(void)' already has a body
Last edited by andwan0; April 29th, 2009 at 06:13 AM.
-
April 29th, 2009, 06:30 AM
#6
Re: CDateTimeCtrl - background color
 Originally Posted by andwan0
And also add BOOL OnEraseBkgnd(CDC* pDC); to the header file too 
This is done by the wizard. Maybe you didn't follow the instructions above!?
-
April 29th, 2009, 06:43 AM
#7
Re: CDateTimeCtrl - background color
Manually derived from CDateTimeCtrl with no wizard....
btw, does this paint the box (of the drop down bit)?
-
April 29th, 2009, 06:48 AM
#8
Re: CDateTimeCtrl - background color
No, this box is not belong to the *background*.
Victor Nijegorodov
-
April 29th, 2009, 07:28 AM
#9
Re: CDateTimeCtrl - background color
Not bad for an eight year old thread!
Be sure to rate those who help!
-------------------------------------------------------------
Karl - WK5M
PP-ASEL-IA (N43CS)
PGP Key: 0xDB02E193
PGP Key Fingerprint: 8F06 5A2E 2735 892B 821C 871A 0411 94EA DB02 E193
-
April 29th, 2009, 07:34 AM
#10
Re: CDateTimeCtrl - background color
Victor Nijegorodov
-
April 29th, 2009, 09:11 AM
#11
Re: CDateTimeCtrl - background color
Some things never die.....
-
April 29th, 2009, 09:52 AM
#12
-
April 30th, 2009, 05:37 AM
#13
Re: CDateTimeCtrl - background color
I truly hope, at least the OP is still alive.
-
August 12th, 2011, 05:11 PM
#14
Re: CDateTimeCtrl - background color
This is a very nice solution, but it unfortunately doesn't appear to work on Windows 7.
Anybody know a solution under Windows 7?
-
August 15th, 2011, 01:15 PM
#15
Re: CDateTimeCtrl - background color
 Originally Posted by wbrouhaha
This is a very nice solution, but it unfortunately doesn't appear to work on Windows 7.
Anybody know a solution under Windows 7?
And probably it doesn't appear to work under Windows 8 and further Windows...
Please, if you have a new problem, open a new thread and don't wake up very old ones!
[ Thread closed ]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|