?
Solved

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

Posted on 2008-10-15
6
Medium Priority
?
1,969 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

 
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

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

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

Introduction: Dialogs (2) modeless dialog and a worker thread.  Handling data shared between threads.  Recursive functions. Continuing from the tenth article about sudoku.   Last article we worked with a modal dialog to help maintain informat…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

770 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