-
January 5th, 2005, 09:09 AM
#1
CComboBox - hide dropdown/color of highlight
Hi,
I have created a CMyCombo class derived from CComboBox, which I use for a color picker dropdown. There are two issues I desperately need some help to solve:
1.
If "No Fill" is selected in the color picker dialog, I need to set the text "No Fill" in the combobox object. This should be done without displaying the dropdownlist.
I've tried using ShowDropDown(FALSE), but this method doesn't have any affect. The dropdownlist flickers at the same time as the color picker is displayed.
How should I hide the dropdownlist, and at the same time set/remove the text to be displayed?
2.
The other issue is the highlight of the CComboBox object.
I need to entirely remove the highligting, or I'll have to set the same color on the highlighting as on the background color of the combo box.
So how to get hold of and set the color of the highlighted area?
Any help will be greately appreciated!
-
January 5th, 2005, 10:07 AM
#2
Re: CComboBox - hide dropdown/color of highlight
Override DrawItem() and do something like this:
Code:
// selected
if( ((lpDraw->itemAction & ODA_SELECT) == ODA_SELECT) &&
((lpDraw->itemState & ODS_SELECTED) == ODS_SELECTED))
{
pDC->FillSolidRect(&lpDraw->rcItem,::GetSysColor(COLOR_WINDOW));
// or
// pDC->FillSolidRect(&lpDraw->rcItem, DESIRED_COLOR);
pDC->SetTextColor( DESIRED_COLOR );
}
// not selected
else
{
pDC->FillSolidRect(&lpDraw->rcItem,::GetSysColor(COLOR_WINDOW));
pDC->SetTextColor( DESIRED_COLOR );
}
...
-
January 6th, 2005, 08:29 AM
#3
Re: CComboBox - hide dropdown/color of highlight
I've tried to override the DrawItem(...) in order to get this working, but for some reason it seems like DrawItem(...) is never called.
Declaration of class:
class CAgrColorCombo : public CComboBox
Initialization of the CComboBox object:
newStyle = WS_TABSTOP|WS_CHILD|WS_VISIBLE | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED;
BOOL bRet = Create( newStyle, wndRect, parent, Id );
Then I have overridden
DrawItem(..)
MeasureItem(...) //Do nothing
CompareItem(...) //Do nothing
What could the reason be for DrawItem never to be called?
Cheers!
-
January 6th, 2005, 01:08 PM
#4
Re: CComboBox - hide dropdown/color of highlight
Originally Posted by hubba09
Initialization of the CComboBox object:
newStyle = WS_TABSTOP|WS_CHILD|WS_VISIBLE | CBS_DROPDOWNLIST | CBS_OWNERDRAWFIXED;
BOOL bRet = Create( newStyle, wndRect, parent, Id );
Where is this code taken from?
-
January 6th, 2005, 01:27 PM
#5
Re: CComboBox - hide dropdown/color of highlight
Used that code to initialize the CCombobox object.
I have rewritten my code and I have finally got it working.
Thanks for your help!
Cheers
-
September 28th, 2015, 12:53 PM
#6
Re: CComboBox - hide dropdown/color of highlight
Hi Cilu....
This code is working for applying background color... but however the text added to dropdown is not visible. Any idea of how to get rid this.
-
October 2nd, 2015, 03:00 PM
#7
Re: CComboBox - hide dropdown/color of highlight
Originally Posted by yash35
Hi Cilu....
This code is working for applying background color... but however the text added to dropdown is not visible. Any idea of how to get rid this.
Could you describe your problem more clear?
Victor Nijegorodov
-
October 3rd, 2015, 09:26 AM
#8
Re: CComboBox - hide dropdown/color of highlight
Originally Posted by VictorN
Could you describe your problem more clear?
Hi Victor,
I want to color the always visible edit field part of combobox and dropdownlist part which is visible after clicking arrow of combobox to be in orange color.
So i am trying to override the DrawItem method. Below is my code. The method is firing but however the combobox and its contents itself is not visible. Am I missing any code here?
Code:
void CMCombo::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
{
LPCTSTR lpszText = (LPCTSTR)lpDrawItemStruct->itemData;
CDC dc;
dc.Attach(lpDrawItemStruct->hDC);
COLORREF crOldTextColor = dc.GetTextColor();
COLORREF crOldBkColor = dc.GetBkColor();
// If this item is selected, set the background color
// and the text color to appropriate values. Erase
// the rect by filling it with the background color.
if ((lpDrawItemStruct->itemAction & ODA_SELECT) &&
(lpDrawItemStruct->itemState & ODS_SELECTED))
{
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(33023);
dc.FillSolidRect(&lpDrawItemStruct->rcItem, 33023);
}
else
{
dc.FillSolidRect(&lpDrawItemStruct->rcItem, 33023);
}
// Draw the text.
dc.DrawText(
lpszText,
(int)_tcslen(lpszText),
&lpDrawItemStruct->rcItem,
DT_CENTER | DT_SINGLELINE | DT_VCENTER);
// Reset the background color and the text color back to their
// original values.
dc.SetTextColor(crOldTextColor);
dc.SetBkColor(33023);
}
-
October 5th, 2015, 03:50 AM
#9
Re: CComboBox - hide dropdown/color of highlight
What does this magic number 33023 mean?
Victor Nijegorodov
-
October 5th, 2015, 10:23 AM
#10
Re: CComboBox - hide dropdown/color of highlight
Originally Posted by VictorN
What does this magic number 33023 mean?
It is integer value of orange color....
-
October 7th, 2015, 05:40 AM
#11
Re: CComboBox - hide dropdown/color of highlight
Last edited by Igor Vartanov; October 7th, 2015 at 05:43 AM.
Best regards,
Igor
-
October 7th, 2015, 09:00 AM
#12
Re: CComboBox - hide dropdown/color of highlight
Igor, Thanks for saving my life..... I was badly in need of this code. Right code @ right time
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
|