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 ?
mike_marquetAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AndyAinscowFreelance programmer / ConsultantCommented:
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
Cloud Class® Course: MCSA MCSE Windows Server 2012

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

AndyAinscowFreelance programmer / ConsultantCommented:
Just to be certain - is the PreSubclassWindow is being called.  Put a breakpoint in it and see if it is hit.
0
AndyAinscowFreelance programmer / ConsultantCommented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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
AndyAinscowFreelance programmer / ConsultantCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
AndyAinscowFreelance programmer / ConsultantCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.