|
-
December 14th, 2002, 04:43 AM
#1
Problem with Dropdownlist Combo box
Simple Question first What is the Difference between CWnd::CtlColor and CWnd::OnCtlColor?
my real problem is that I am creating a flat combobox for an application with some success. I am able to change the color of text and background and overall appearance by handling WM_PAINT and WM_CTLCOLOR messages but when my Combo box style is set to CBS_DROPDOWMLIST, I cannot change the background color or the Text colot in then Static control display window. anyone has suggestions?
CFlatCombo::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
pDC->SetTextColor(m_crText);
pDC->SetBkColor(m_crBkColor);
pDC->SetBkMode(TRANSPARENT);
//The value of this brush is set in CFLatCombo::SetBkColor
return m_brBkgnd;
}
CFlatCombo::OnPaint()
{
// Most of the Drawing is omitted
CPaintDC dc(this);
CRect rcCombo;
PAINTSTRUCT ps;
BeginPaint(&ps);
GetClientRect(&rcCombo);
CBrush* pBkBrush = new CBrush(m_crBkColor);
CPen* pBkPen = new CPen(PS_SOLID, 1, RGB(0,0,0));
CBrush* pOldBrush = dc.SelectObject(pBkBrush);
CPen* pOldPen = dc.SelectObject(pBkPen);
dc.Rectangle(rcCombo);
EndPaint(&ps);
dc.SelectObject(pOldBrush);
dc.SelectObject(pOldPen);
delete pBkBrush;
delete pBkPen;
}
-
December 14th, 2002, 06:49 AM
#2
Sample code to change the color of static controls: use this code in OnCtrlcolor() function dependiong on your requirement:
//Blue color for a specific control on anytype (say IDC_EDIT2 edit control)
HBRUSH hbrBlue=CreateSolidBrush(RGB(0,0,255));
//to change all statis control colors
if(nCtlColor==CTLCOLOR_STATIC)
{
pDC->SetBkColor(RGB(0,255,0));
return hbrGreen;
}
//To change a specific static control color, first give an unique resource id to that static and use this code
if(pWnd->GetDlgCtrlID()==IDC_STATIC_XYZ)
{
pDC->SetBkColor(RGB(0,0,255));
return hbrBlue;
}
Hope this helps
skpradhan
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
|