views:

115

answers:

3

Hi !

I wanted to create a custom combo box like this (as in MS Word),

alt text

Are there any Win32 API calls (I can't use MFC) to get this job done, (like ChooseColor() or ChooseFont()? If there aren't any, can anyone please tell me how to do this? Thanks you.

Regards,

EDIT: Creating the Owner-Drawn Dialog Box!! Is this the only way ? http://msdn.microsoft.com/en-us/library/bb775794%28VS.85%29.aspx#creating_square_meal

A: 

You can derive from WTL::CComboBox. You'd have to implement the message handlers for

  • WM_MEASUREITEM / OCM_MEASUREITEM to do the size measurements of your combo box items
  • WM_DRAWITEM / OCM_DRAWITEM to do the drawing itself. You don't need bitmaps really, you could simply draw using GDI.
Sebastian
Thanks. But I can't use any of those. Only native win32 API calls. :(
Morpheus
btw, is that mean, there isn't a single API call for this?
Morpheus
A: 

In Win32 this is called a owner-drawn combobox. A good startpoint in the online dicumentation is here:

http://msdn.microsoft.com/en-us/library/bb775794%28VS.85%29.aspx#creating_owner_drawn

RED SOFT ADAIR
Thanks. It use the icon to draw those custom bitmaps, so can I change the size of the icons in a combo box ? (bcz, I want to draw those same as above image, not just as a icon).
Morpheus
You can draw what and however you want. See the documentation.
RED SOFT ADAIR
+1  A: 

You have some options to solve your problem:

  1. All common controls supports WM_SETFONT, so if you find a Font which has all line elements which you need, you can change font of the combobox control and fill items with corresponding textes.
  2. There are ComboBoxEx control which combines images with textes (see http://msdn.microsoft.com/en-us/library/bb775738(VS.85).aspx). Be careful, what part of items will be selected (just try it). If you can a little change your requirements to the combobox control you will be able to use this.
  3. You can use owner-draw combo-box. Then you are absolutely free, but your code can be a liitle longer and you should be more carful if you works with non-standard color shema of windows or a non-default theams. I'll recommend you use functions GetSysColor in this case.

You should deceide youself whay way is the best for your project requirements.

Oleg
Nice one. I think option 2 is what I need. I'll look into it. Thank you very much.
Morpheus