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

  • The impact of a data loss event can be significant. Real-time data is essential to remaining competitive. Many companies can no longer afford to rely on a truck arriving each day to take backup tapes offsite. For most companies, a cloud backup and recovery solution will eliminate, or significantly reduce, IT resources related to the mundane task of backup and allow your resources to be redeployed to more strategic projects. The cloud - can now be comfortable for you – with 100% recovery from anywhere all …

  • The latest release of SugarCRM's flagship product gives users new tools to build extraordinary customer relationships. Read an in-depth analysis of SugarCRM's enhanced ability to help companies execute their customer-facing initiatives from Ovum, a leading technology research firm.

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds