quick question on color
-
i am using onctlcolor message to set the the background color of edit controls. the problem is that the background only changes background color if there is text in the control and only for the length of the text. can the background color be changed regardless of what is in the control for data? thank you
-
i am using onctlcolor message to set the the background color of edit controls. the problem is that the background only changes background color if there is text in the control and only for the length of the text. can the background color be changed regardless of what is in the control for data? thank you
-
i am using onctlcolor message to set the the background color of edit controls. the problem is that the background only changes background color if there is text in the control and only for the length of the text. can the background color be changed regardless of what is in the control for data? thank you
Don't forget to invalidate the entire region of the controls to force a paint. Jeremy L. Falcon "The One Who Said, 'The One Who Said...'" Homepage : Feature Article : Sonork = 100.16311
-
Sounds like you're using
SetBgColor()
. Instead (or in addition) create a solid color brush and return that._**Developers that like shiny objects also dig case mods and scratch-and-sniff stickers.
**_
Klaus Probst, The Lounge
no i am using setbkcolor() this is the onctlcolor it works the ok but it only changes the color behind the text not all the background of the control. if there is no text the color will not change at all. when i want the color to change i call Invalidate() HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); int nCtrl = pWnd ->GetDlgCtrlID(); switch(nCtrl){ case IDC_BCOLOR: pDC->SetBkColor(RGB(m_red,m_green,m_blue)); break; /////////////////////plus more } return hbr; }
-
no i am using setbkcolor() this is the onctlcolor it works the ok but it only changes the color behind the text not all the background of the control. if there is no text the color will not change at all. when i want the color to change i call Invalidate() HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor); int nCtrl = pWnd ->GetDlgCtrlID(); switch(nCtrl){ case IDC_BCOLOR: pDC->SetBkColor(RGB(m_red,m_green,m_blue)); break; /////////////////////plus more } return hbr; }
jafrazee wrote: no i am using setbkcolor() Sorry, typo (yes i am too lazy to bother checking each post against MSDN before submitting ;) ) What you need to do is this (assume you've added a member to your class of type HBRUSH and named it m_hBrush, since you'll need to delete this when done with it):
HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int nCtrl = pWnd->GetDlgCtrlID();
switch (nCtrl)
{
case IDC_BCOLOR:
pDC->SetBkColor(RGB(m_red,m_green,m_blue));
if ( NULL != m_hBrush )
::DeleteObject(m_hBrush);
m_hBrush = ::CreateSolidBrush(RGB(m_red,m_green,m_blue));
hbr = m_hBrush;
break;
/////////////////////plus more
}
return hbr;
}Alternately, you could just keep a handle of a pre-created brush as a class member and return that. Explanation: The background color set using
SetBkColor()
applies to the text only, as you've noticed. In order to color the rest of the background, you need to return a brush of the appropriate color. This is what the code in bold does above. Windows does not delete the brush when it is done with it, so you must remember to do so after the window is destroyed (or before creating and returning a different brush, as shown)._**Developers that like shiny objects also dig case mods and scratch-and-sniff stickers.
**_
Klaus Probst, The Lounge
-
jafrazee wrote: no i am using setbkcolor() Sorry, typo (yes i am too lazy to bother checking each post against MSDN before submitting ;) ) What you need to do is this (assume you've added a member to your class of type HBRUSH and named it m_hBrush, since you'll need to delete this when done with it):
HBRUSH PREFS::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
int nCtrl = pWnd->GetDlgCtrlID();
switch (nCtrl)
{
case IDC_BCOLOR:
pDC->SetBkColor(RGB(m_red,m_green,m_blue));
if ( NULL != m_hBrush )
::DeleteObject(m_hBrush);
m_hBrush = ::CreateSolidBrush(RGB(m_red,m_green,m_blue));
hbr = m_hBrush;
break;
/////////////////////plus more
}
return hbr;
}Alternately, you could just keep a handle of a pre-created brush as a class member and return that. Explanation: The background color set using
SetBkColor()
applies to the text only, as you've noticed. In order to color the rest of the background, you need to return a brush of the appropriate color. This is what the code in bold does above. Windows does not delete the brush when it is done with it, so you must remember to do so after the window is destroyed (or before creating and returning a different brush, as shown)._**Developers that like shiny objects also dig case mods and scratch-and-sniff stickers.
**_
Klaus Probst, The Lounge