Dave's Brain

Browse - Programming Tips - How do I initialize a class I made that's derived from an existing MFC class?

Date: 2000oct14
Framework: MFC
OS: Windows
Language: C/C++

Q.  How do I initialize a class I made that's derived from an existing MFC class?

A.  You can not do it in the constructor because the window does not exist.
You can not do it in OnCreate() either.  I am not aware of any Windows
messages you can catch on all Windows versions.  So it seems the best way
is to override the PreSubclassWindow() function.

In your .h file do this:

class CMyListCtrl : public CListCtrl { private: // ... //{{AFX_MSG(CMyListCtrl) virtual void PreSubclassWindow(); //}}AFX_MSG // ... };
In your .cpp file do this:
void CMyListCtrl::PreSubclassWindow() { // Place your init code here. // Since the Window exists you can change styles, colors, etc. CListCtrl::PreSubclassWindow(); // Call the base class's PreSubclassWindow() just in case }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.