[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1267
  • Last Modified:

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 ?
0
mike_marquet
Asked:
mike_marquet
  • 7
  • 5
  • 2
  • +1
2 Solutions
 
AndyAinscowCommented:
Do you need to remove a different style setting that conflicts with the variabledraw?
0
 
mahesh1402Commented:
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
0
 
mike_marquetAuthor Commented:
I want to make a standalone class to put into a library, therefore, don't want to write code in the parent class.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
AndyAinscowCommented:
Just to be certain - is the PreSubclassWindow is being called.  Put a breakpoint in it and see if it is hit.
0
 
AndyAinscowCommented:
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 !
0
 
AndyAinscowCommented:
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).
0
 
mike_marquetAuthor Commented:
PreSubclassWindow is called but it seems to be to late to change this style.

SubclassWindow is never called !
0
 
AndyAinscowCommented:
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)
0
 
mike_marquetAuthor Commented:
I have a valid HWND in PreSubclassWindow
0
 
AndyAinscowCommented:
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);
}
0
 
mike_marquetAuthor Commented:
I have already written an ASSERT in the PreSubclassWindow, but would just try to find a way to hide it.
0
 
DanRollinsCommented:
In this thread, respected EE Expert migel suggests that this is one of those styles that cannot be changed after creation:
     http://www.experts-exchange.com/Programming/Programming_Languages/MFC/Q_11443919.html
and he described the steps to create a new control with the desired attributes and populate it from the contents of the existing one.

-- Dan
0
 
AndyAinscowCommented:
What I suggested in my previous comment is to provide a mechanism to warn any other developer that it won't work and why it wont work.
To change the style in the resource editor (prior to subclassing) is rapidly done.  A similar check in the OnCreate will also trap the case of a developer using Create to create a control dynamically.
The message box is to provide a warning.  The ASSERT will prevent the app from continuing in DEBUG mode.  Application development is usually performed in DEBUG mode.
0
 
mike_marquetAuthor Commented:
When no way, I still stay with my ASSERT.
0
 
DanRollinsCommented:
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" :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 7
  • 5
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now