Icon Picker Combo Box

To use this icon combo box, follow these simple steps.

  1. Include IconComboBox.cpp and IconComboBox.h in your project.
  2. In the resource editor create a regular combobox with at least the following styles: DropList, OwnerDraw Variable, Has Strings
  3. Create a control member variable for the combobox in VC's classwizard.
  4. Replace CComboBox with CIconComboBox in your  .h file.


Figure1 - Sample picture of the IconComboBox in action

After the IconComboBox is created, you can use the following methods to insert, select and remove icons:

public:
virtual int AddIcon(LPCTSTR lpszIconFileName);
virtual int InsertIcon(int nIndex, LPCTSTR lpszIconFileName);
virtual int SelectIcon(LPCTSTR lpszIconFileName);
virtual int SelectIcon(int nIndex);
virtual int DeleteIcon(LPCTSTR lpszIconFileName);
virtual int DeleteIcon(int nIndex);

The following method can be overrided to paint the icon in a different way. Normally the icon is drawn centered within the combobox.  

protected:
virtual void OnOutputIcon(LPDRAWITEMSTRUCT lpDIS, BOOL bSelected);

It is important that the style Has Strings (CBS_HASSTRINGS) is specified, because the filename of the icon is actually stored in the combobox for later use if you select or delete an icon. The width of the combobox is decided by you when you create the control. The height can be set manually with the following statement:

m_cbMyIconComboBox.SetItemHeight(-1, m_cbMyIconComboBox.m_sizeIcon.cy + 6);

where m_sizeIcon.cy are a standard icon height (SM_CYICON).
Download source files - 2 KB



Comments

  • help about icon combox

    Posted by miser on 04/16/2004 01:55am

    dear sir, i am a student ,in my homework,i want to add an icon combox, but i cannot do it. i am a new one in the disscussion,i cannot load my icon in the combox ,can you send me a project about icon combox.thank you!

    Reply
  • Icon Combo

    Posted by Legacy on 02/09/2004 12:00am

    Originally posted by: Srinivas

    But Why am I getting Compilation Errors:

    \IconCombo\IconCombo.vcl(30):G:\usr\kgs\downs\IconCombo\IconComboBox.cpp(31) : error C2039: 'ExtractIcon' : is not a member of '`global namespace''
    \IconCombo\IconCombo.vcl(31):G:\usr\kgs\downs\IconCombo\IconComboBox.cpp(31) : error C2065: 'ExtractIcon' : undeclared identifier
    2 occurrence(s) have been found.

    Reply
  • If it is a imagelist instead of some icons,how can I do it

    Posted by Legacy on 04/20/2003 12:00am

    Originally posted by: zhengwq

    I wanted to allow certain image selection in one of my projects.The image is from a imagelist.How can I do it?
    

    Reply
  • Transparency

    Posted by Legacy on 10/04/2002 12:00am

    Originally posted by: Geny

    I would like to know how to draw icon with transparency in the custom combo box if possible.

    Reply
  • What about using Borland?

    Posted by Legacy on 05/21/2002 12:00am

    Originally posted by: mike

    i can't get this to compile under Borland. Will it even work under borland?

    Reply
  • I've yet to get this working.

    Posted by Legacy on 05/05/2002 12:00am

    Originally posted by: blip

    I get a err message when I load the token.

    Reply
  • how can i do this in vb?

    Posted by Legacy on 02/24/2002 12:00am

    Originally posted by: Mital

    Please Tell me how can i make this thing in vb

    Reply
  • iconlist in combo box

    Posted by Legacy on 02/15/2002 12:00am

    Originally posted by: Shikha Gupta

    Can I have an icon list in the list box of combo box ? So that icons can be selected off and on !

    Reply
  • icon picker using vb?

    Posted by Legacy on 01/03/2002 12:00am

    Originally posted by: Jennie Ng

    Hello,

    Is there a way to add icon to a combo box using vb?

    Thanks
    Jennie

    Reply
  • how can I change the height of combobox

    Posted by Legacy on 11/15/2001 12:00am

    Originally posted by: xyq

    it means that this program can display the icon in
    combobox,but the height of combobox befor clicking the
    combobox doesn't fit the icon.
    hope your answer!


    thanks a million!

    Reply
  • Loading, Please Wait ...

Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • Companies undertaking an IT project need to find the right balance between cost and functionality. It's important to start by determining whether to build a solution from scratch, buy an out-of-the-box solution, or a combination of both. In reality, most projects will require some system tailoring to meet business requirements. Decision-makers must understand how much software development is enough and craft a detailed implementation plan to ensure the project's success. This white paper examines the different …

  • On-demand Event Event Date: February 12, 2015 The evolution of systems engineering with the SysML modeling language has resulted in improved requirements specification, better architectural definition, and better hand-off to downstream engineering. Agile methods have proven successful in the software domain, but how can these methods be applied to systems engineering? Check out this webcast and join Bruce Powel Douglass, author of Real-Time Agility, as he discusses how agile methods have had a tremendous …

Most Popular Programming Stories

More for Developers

RSS Feeds

Thanks for your registration, follow us on our social networks to keep up-to-date