Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2008-10-15
6
Medium Priority
?
1,976 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 900 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 3

Assisted Solution

by:Naveen_R
Naveen_R earned 900 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

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Question has a verified solution.

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

Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
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.
Suggested Courses

810 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