CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12
  1. #1
    Join Date
    Nov 2004
    Posts
    23

    Question 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!

  2. #2
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    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 );
      }
    
    ...
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  3. #3
    Join Date
    Nov 2004
    Posts
    23

    Unhappy 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!

  4. #4
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: CComboBox - hide dropdown/color of highlight

    Quote 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?
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  5. #5
    Join Date
    Nov 2004
    Posts
    23

    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

  6. #6
    Join Date
    Sep 2015
    Posts
    4

    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.

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CComboBox - hide dropdown/color of highlight

    Quote Originally Posted by yash35 View Post
    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

  8. #8
    Join Date
    Sep 2015
    Posts
    4

    Re: CComboBox - hide dropdown/color of highlight

    Quote Originally Posted by VictorN View Post
    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,Name:  Combobox.png
    Views: 730
    Size:  636 Bytes
    		(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);
    }

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: CComboBox - hide dropdown/color of highlight

    What does this magic number 33023 mean?
    Victor Nijegorodov

  10. #10
    Join Date
    Sep 2015
    Posts
    4

    Re: CComboBox - hide dropdown/color of highlight

    Quote Originally Posted by VictorN View Post
    What does this magic number 33023 mean?
    It is integer value of orange color....

  11. #11
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    6,620

    Re: CComboBox - hide dropdown/color of highlight

    Last edited by Igor Vartanov; October 7th, 2015 at 05:43 AM.
    Best regards,
    Igor

  12. #12
    Join Date
    Sep 2015
    Posts
    4

    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
  •  





Click Here to Expand Forum to Full Width

Featured