Link to home
Start Free TrialLog in
Avatar of mike_marquet
mike_marquet

asked on

Adding the CBS_OWNERDRAWVARIABLE after the combobox is created

How can I add the CBS_OWNERDRAWVARIABLE after the combobox control is created ?

I have try this :

void CExtendedComboBox::PreSubclassWindow()
 {
  ModifyStyle(0, CBS_OWNERDRAWVARIABLE | CBS_HASSTRING);

  CComboBox::PreSubclassWindow();
 }

But it has no effect.

Any idea ?
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Do you need to remove a different style setting that conflicts with the variabledraw?
You can use CBS_OWNERDRAWFIXED; it's just that you need to put an OnMeasureItem() handler in the parent window's class, since the WM_MEASUREITEM message is sent BEFORE the combo box is created.

MAHESH
Avatar of mike_marquet
mike_marquet

ASKER

I want to make a standalone class to put into a library, therefore, don't want to write code in the parent class.
Just to be certain - is the PreSubclassWindow is being called.  Put a breakpoint in it and see if it is hit.
Oh - as this is the **Pre** function is it actually attached to the combo at this point?  In other words is your code 'failing' because you aren't changing the style of the combo !
Give it a try in the SubclassWindow function instead (call the base function first, then ModifyStyle, also check with TRACE/Breakpoint that it gets called).
PreSubclassWindow is called but it seems to be to late to change this style.

SubclassWindow is never called !
PresubclassWindow - have you checked that there is a valid HWND at that point?

If there isn't then try SubclassDlgItem (there are two functions for subclassing! why - that I don't know)
I have a valid HWND in PreSubclassWindow
I've had a look at it here and done some searching.  It seems like there is no (easy) way to do it.

I would recommend that in the OnCreate and PreSubclassWindow functions you check the style, force a halt if it doesn't have the required styles.  
if(!(GetStyle() & CBS_OWNERDRAWVARIABLE))
{
  AfxMessageBox("Requires Owner Draw Variable style");
  ASSERT(false);
}
I have already written an ASSERT in the PreSubclassWindow, but would just try to find a way to hide it.
ASKER CERTIFIED SOLUTION
Avatar of DanRollins
DanRollins
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
When no way, I still stay with my ASSERT.
A interesting side note:  
VisualBasic programmers might be amused to hear that some "window attributes" cannot be changed easily at any time... because the VB libraries have been written to overcome such Win32 API limitations.  That huge VB runtime libary includes code to automatically and transparently destroy and recreate windows when necessary.  In C++, we are working a little bit "closer to the metal" :-)