Change style of CListCtrl in creation

I have a CListCtrl drived class CListCtrlEx, it is created from resource
but I want to disregard
(give assertions first) of its styles
and set a new one on its creation.
for this I have a hanler for WM_CREATE
int CListCtrlEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
      if (CListCtrl::OnCreate(lpCreateStruct) == -1)
            return -1;      
      return 0;

and I have a dialog app, with
CListCtrl resource on it.
      CListCtrlEx      m_ctrListEx;

I know that m_ctrListEx is created
but it newer goes to my OnCreate
handler ???? why ??? and is this the place I should put my assertions and set the new style. I also tried
overrides create, and precreate
non of them seemed visited ????

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.

IF you have DDX entry for your list control then OnCreate is not going to be called...
The answer follows. But you still may be interested to go there for the discussion detais.

> When I implement an OnCreate message
> handler for this control it seems
> never been called. Could someone
> tell me why this is happening.

You can use your controls in two general ways

1) creating new control that hasn't been existing in your dialog before
2) connecting your control class to already existing items of dialog template ( subclass )

In the first case the OnCreate message handler gets called. In the second case the corresponding DDX method subclasses the window with specified ID to your control class. (OnCreate never been called )

If you need to do some special initializations for your control you have to cover both cases. And I don't like very much the way suggested by Naveenkohli form general point of view, sorry. As soon as you have the special control class declared it's better to have as much job done in the implementation of the class as possible. Then you don't need to repeat the job every time you include the control to some of your dialogs.
As for initializations they could be done ( for instance ) the following way:

class CMyCtrl : public CBaseClass

// Overrides
// ClassWizard generated virtual function overrides
virtual void PreSubclassWindow();

// Implementation
virtual void InitialUpdate(BOOL bFromCreate);

// Generated message map functions
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);


// OnCreate message handler calls the new InitialUpdate for initializations (1)
int CMyCtrl::OnCreate(LPCREATESTRUCT lpCreateStruct)
if (CBaseClass::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;

// PreSubclassWindow override calls the new InitialUpdate for initializations (2)
void CMyCtrl::PreSubclassWindow()
if (GetParent())

// InitialUpdate provides necessary initializations
void CMyCtrl::InitialUpdate(BOOL bFromCreate)

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
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

Generally, PrecreateWindow()is the place where you would change the window style prior to display ... I'm curious why you say you've tried that and the function never gets called....
Because the first MFC DDX call provides just subclass EN EXISTING control window to user defined class. This is another calling sequence: PreSubclassWindow, ... See MFC sources for the details. There are some window styles that is possible to change on the fly. Others should be set properly in a dialog template.
hasAuthor Commented:
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.