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

Date: 2000oct14 Framework: MFC OS: Windows Language: C/C++ Q. MFC: How to 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 }