• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1333
  • Last Modified:

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
as
int CListCtrlEx::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
      lpCreateStruct->style = LVS_SHOWSELALWAYS | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP;
      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 ????

0
has
Asked:
has
1 Solution
 
naveenkohliCommented:
IF you have DDX entry for your list control then OnCreate is not going to be called...
0
 
abk102299Commented:
0
 
abk102299Commented:
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
//{{AFX_VIRTUAL(CMyCtrl)
protected:
virtual void PreSubclassWindow();
//}}AFX_VIRTUAL

// Implementation
public:
virtual void InitialUpdate(BOOL bFromCreate);

// Generated message map functions
protected:
//{{AFX_MSG(CMyCtrl)
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
//}}AFX_MSG

};

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

// PreSubclassWindow override calls the new InitialUpdate for initializations (2)
void CMyCtrl::PreSubclassWindow()
{
if (GetParent())
InitialUpdate(FALSE);
CBaseClass::PreSubclassWindow();
}

// InitialUpdate provides necessary initializations
void CMyCtrl::InitialUpdate(BOOL bFromCreate)
{
....
}
0
Learn to develop an Android App

Want to increase your earning potential in 2018? Pad your resume with app building experience. Learn how with this hands-on course.

 
captainkirkCommented:
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....
0
 
abk102299Commented:
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.
0
 
hasAuthor Commented:
thanks
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now