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

  • Organizations are increasingly gravitating toward mobile-first application development as they assess the need to revamp their application portfolios to support touch computing and mobility. Consumerization has brought higher expectations for application usability along with the mobile devices themselves. Enterprises are increasingly shifting their new application acquisitions and development efforts toward mobile platforms. With this backdrop, it is natural to expect application platform vendors to invest in …

  • Thanks to wide spread cloud hosting and innovations small businesses can meet and exceed the legacy systems of goliath corporations. Explore the freedom to work how you want, with a phone system that will adapt to your evolving needs and actually save you lots of expense—read Get an Enterprise Phone System without High Cost and Complexity. The article clearly illustrates: The only hardware you'll need is phone equipment for advanced voice and fax. How to join all your employees, mobile devices, …

Most Popular Programming Stories

More for Developers

RSS Feeds

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