Solved

Bitmap in a combo box.

Posted on 1998-08-03
3
464 Views
Last Modified: 2013-11-19
How do I add a little bitmap next to each item in a combo box?  

Thanks.
0
Comment
Question by:syu
3 Comments
 

Expert Comment

by:nari
Comment Utility
Use owner drawn combo boxes.While creating the combo box using resource editor
set the styles of the combo box to owner draw(fixed or variable) by clicking right mouse
button on after highlighting combo box.Afterwards overwrite DrawItem(..) member
of Combo box then the world is yours.Look in vc++ for more help.
0
 

Author Comment

by:syu
Comment Utility
If I overwrite DrawItem(), that means I need to derive a class from CComboBox!  Is there any way that I don't need to create a class to put a bitmap on the combo box?  If no, please give details on how to put bitmap in DrawItem().  Set multiple columns, etc.

0
 
LVL 1

Accepted Solution

by:
payn earned 20 total points
Comment Utility
Why don't you want to derive a class from CComboBox? That's by far the easiest way to do it. The code in MFC's CCheckListBox is a good place to start if you reconsider, and ask specific questions if you get stuck.

However, if you're dead set against it, no, you don't have to derive from CComboBox. An owner-draw control actually sends its messages to the control's parents. The default MFC way to handle this is to reflect them to the controls (it does _not_ call the control's virtual DrawItem, MeasureItem, DeleteItem, as the documentation claims... but the effect is the same, I guess). This makes them effectively "self-draw" rather than "owner-draw." Which, again, is easier to handle, not harder.

Still, you can stop MFC from doing this if you want.

Instead of overriding DrawItem in CComboBox, catch the Windows WM_DRAWITEM message in your CDialog. Make sure not to call the base class version at the end, or it'll reflect the message to the CComboBox, which you apparently don't want.

One more possibility: Fake the combo box by using an edit control and, instead of a listbox, a list common control. Let Win32 draw the icons and manage the columns and all that for you...


0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now