Solved

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

Posted on 2008-10-15
6
1,942 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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…
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.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

743 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

12 Experts available now in Live!

Get 1:1 Help Now