Solved

Owner Drawn ComboBox (Drop List). Static Text Box shrinks

Posted on 2008-10-15
6
1,952 Views
Last Modified: 2013-11-20
I've created an Owner-Draw CComboBox and derived a class from it. This works and my owner-draw processing works correctly (basically just displaying an abbreviated version of the text of each item).

On the dialog designer, the combo box is 12 dialog units high, which is what I want.

However, when the program runs, it shrinks to about 9 DLU high and the text in both the text box section and in the list section is terribly squashed up. When I turn Owner-Draw off, the correct height of 12 DLU is restored.

What's going on here ?
All I am overloading is the DrawItem() member function.
Do I need to override something else, in order to tell Windows what size of rectangle I want ?

((This isn't the usual question of "how do I set the height of the drop box part". I've solved that one.))
0
Comment
Question by:muttley3141
  • 4
  • 2
6 Comments
 
LVL 3

Accepted Solution

by:
Naveen_R earned 300 total points
ID: 22727934
Have you handled WM_MEASUREITEM message and set the height from it?

While owner drawing a combo, we need to handle this message and Inside the handler of this message, you have to set the required height in the input structure.
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22728363
I have added a handler for that message but it is never called.
Microsoft documentation say that for CComboBoxes created by the dialog editor, this is correct behavior; that message is only sent if the control's class is created at run-time, or is created with the CBS_OWNERDRAWVARIABLE style. Mine is an "Owner Draw Fixed", so this message never gets sent.
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22728556
This is driving me nuts.
This is what I've done:
I've created the object at run-time, rather than let the dialog editor do whatever it does.
I've created it with CBS_HASSTRINGS and CBS_OWNERDRAWVARIABLE.

Now, the MeasureItem() member of my derived class IS called.

Within that class, I Create and Select a font of the appropriate size (MS Sans Serif 12), call GetTextExtent() and fill the .cx and .cy members thereof into the LPDRAWITEMSTRUCT.

Still, I get a combobox of the wrong size ! The text is squashed within a box apparently 12DLU high. I need 10DLU to make it consistent with the other controls. (I have MS Sans Serif 12 for those as well)
0
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
LVL 3

Assisted Solution

by:Naveen_R
Naveen_R earned 300 total points
ID: 22728597
ok. Any way you can set the height of the combobox explicitly using the SetItemHeight() function. In this function if you specify the item index as -1, the height of combobox will change.
0
 
LVL 1

Author Comment

by:muttley3141
ID: 22729619
I've sort of got it working now. I didn't realise I had to do so much work to create an owner-draw combo box. As you say, I can set it to any height I like. However, I don't know WHAT height to set it to, to "do the same as what dialog designer does". Sure, I can just add a few pixels here and there, but it'll be a maintenance problem if someone decides to change the font/size of other stuff on the dialog.

I tried using GetItemHeight() on a neighboring control, but that just GPFed.

Not a happy ending. I wasn't expecting to do 9 hours investigating just to get some minimal text processing done in a combo box.

When I add the DrawItem() (or was it the MeasureItem() ?) virtual function, the Class Wizard also put a handler in for WM_CALCRECT. Do I need to do anything special with this ? I'm not at the moment.
0
 
LVL 1

Author Closing Comment

by:muttley3141
ID: 31506839
I have decided that implementing an owner-draw combobox was too much work: I have decided to do what I am doing another way. Nevertheless, I learnt a lot of valuable Window-centricisms on the way.

It would be nice to be able to get the behavior to imitate Dialog Designer's behavior, but I don't have the time.

Thank you Naveen R
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Separate into files by filename 12 82
Process filename extension 3 184
Looking for a specific application/software 2 109
abstract class with all non abstract mentods 6 76
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
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.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

806 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