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

  • Today's agile organizations pose operations teams with a tremendous challenge: to deploy new releases to production immediately after development and testing is completed. To ensure that applications are deployed successfully, an automatic and transparent process is required. We refer to this process as Zero Touch Deployment™. This white paper reviews two approaches to Zero Touch Deployment--a script-based solution and a release automation platform. The article discusses how each can solve the key …

  • On-demand Event Event Date: December 18, 2014 The Internet of Things (IoT) incorporates physical devices into business processes using predictive analytics. While it relies heavily on existing Internet technologies, it differs by including physical devices, specialized protocols, physical analytics, and a unique partner network. To capture the real business value of IoT, the industry must move beyond customized projects to general patterns and platforms. Check out this webcast and join industry experts as …

Most Popular Programming Stories

More for Developers

RSS Feeds