-
January 10th, 2012, 07:08 PM
#1
Change color of combo box
Hi, ALL,
Is there a way to change the background color of the combo box? Asking because there is no CTLCOLOR event for this control...
Thank you.
-
January 11th, 2012, 02:49 AM
#2
Re: Change color of combo box
Victor Nijegorodov
-
January 11th, 2012, 02:54 AM
#3
Re: Change color of combo box
You can manually add your own CTLCOLOR functionality, CWnd supports it.
Code:
//in the .h file
afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
//in the .cpp file
ON_WM_CTLCOLOR()
HBRUSH CYourClass::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
int
nCtrlID = pWnd->GetDlgCtrlID();
HBRUSH
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
switch(nCtlColor)
{
case CTLCOLOR_EDIT:
pDC->SetTextColor(RGB(255, 0, 0));
hbr = (HBRUSH)GetStockObject(WHITE_BRUSH);
break;
case CTLCOLOR_STATIC:
pDC->SetTextColor(RGB(0, 0, 128));
pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
hbr = GetSysColorBrush(COLOR_BTNFACE);
break;
case CTLCOLOR_BTN:
pDC->SetTextColor(RGB(128, 0, 0));
pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
hbr = GetSysColorBrush(COLOR_BTNFACE);
break;
case CTLCOLOR_LISTBOX:
pDC->SetTextColor(RGB(128, 0, 0));
pDC->SetBkColor(GetSysColor(COLOR_BTNFACE));
hbr = GetSysColorBrush(COLOR_BTNFACE);
break;
default:
hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
break;
}
return hbr;
}
you can add any MFC functionality manually, or you can use the wizzards . . . doesn't really much matter. . . There are many other settings you can affect from here as well . . .
Perfect Health and Clarity of Mind,
--Victor
-
January 11th, 2012, 03:36 AM
#4
Re: Change color of combo box
Originally Posted by He_That_Is
You can manually add your own CTLCOLOR functionality, CWnd supports it.
That doesn't mean "adding your own CTLCOLOR functionality" but mapping a handler function for WM_CTLCOLOR message.
Originally Posted by He_That_Is
you can add any MFC functionality manually, or you can use the wizzards . . . doesn't really much matter. . . There are many other settings you can affect from here as well . . .
Of course, you can manually map any message but the wizard helps you doing it faster and prevents making mistakes.
What "other settings"?
Last edited by ovidiucucu; January 11th, 2012 at 03:39 AM.
-
February 14th, 2012, 03:13 PM
#5
Re: Change color of combo box
Thank you for the reply, guys.
Is there a straight Win32 way - no MFC?
-
February 14th, 2012, 03:41 PM
#6
Re: Change color of combo box
Originally Posted by OneEyeMan
Thank you for the reply, guys.
Is there a straight Win32 way - no MFC?
Yes. You could implement owner (or custom) drawing for your control.
Or you could try to handle both WM_CTLCOLORLISTBOX and WM_CTLCOLOREDIT messages (sorry, I never did it myself in plain Win32, so I can only guess!(
Last edited by VictorN; February 15th, 2012 at 08:45 AM.
Reason: Some correctins from Ovidiucucu about WM_CTLCOLOR message
Victor Nijegorodov
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
|