Solved

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

Posted on 2008-10-15
6
1,950 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Unix / Linux grid computing 5 149
sum28 challenge 31 107
NotAlone Challenge 20 80
canBalance challenge 34 70
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

863 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

23 Experts available now in Live!

Get 1:1 Help Now