Subclassing dialog boxes 
Author Message
 Subclassing dialog boxes

Dear All,
   I created a series of dialog boxes that share a common
control. I then wanted to create a single parent class for
these CDialog sub-classes to manage this shared control
and resize the windows (they are to be used for a tab
control). To do this I created a dialog resource
containing the shared control and then created a class for
this resource using class wizard. This class contains the
following methods:

CStatsDialog::CStatsDialog(CWnd* pParent /*=NULL*/)


void CStatsDialog::DoDataExchange(CDataExchange* pDX)
        DDX_Control(pDX, IDC_STATLIST, m_StatsList);


BEGIN_MESSAGE_MAP(CStatsDialog, CDialog)

// CStatsDialog message handlers

CStatsDialog::CStatsDialog(UINT idd)
: ChildIDD(idd)


void CStatsDialog::Create(RECT & rect, CGameCompObj &
dlgObj, CWnd * pParent)
        WndRect = rect;
        DlgObj = &dlgObj;
        CDialog::Create(ChildIDD, pParent);


BOOL CStatsDialog::OnInitDialog()
        SetWindowPos(&wndTop, WndRect.left,,
WndRect.right - WndRect.left,
                WndRect.bottom -, NULL);
        // Fill in the stats info ctrl
        m_StatsList.GetTextColor(); <<< Assert fails in
        //m_StatsList.InsertColumn( 0, "Stat Name",
LVCFMT_LEFT, 200, 1);
        //m_StatsList.InsertColumn( 0, "Stat Value",
LVCFMT_LEFT, 100, 1);
        return TRUE;  // return TRUE unless you set the
focus to a control
                      // EXCEPTION: OCX Property Pages
should return FALSE


This class creates a modeless dialog box (because the
subclasses are dialog boxes in a tab control). After this
I created classes for all of the dialog boxes that are to
make up the tab control pages and changed all references
in these classes from CDialog to CStatsDialog. I then
called Create() from the containing dialog box to create
each tab page. The tab control pages appeared as expected.
The problem is that I can't access the shared control
m_StatsList. When I do this the assert fails in

_AFXCMN_INLINE COLORREF CListCtrl::GetTextColor() const
        { ASSERT(::IsWindow(m_hWnd)); return
(COLORREF) ::SendMessage(m_hWnd, LVM_GETTEXTCOLOR, 0,
0L); }

in AFXCMN.INI (ie. m_hWnd == NULL).

Can anyone suggest why I can't access the shared control?

   Thanks for any help,


Fri, 17 Sep 2004 08:30:42 GMT  
 [ 1 post ] 

 Relevant Pages 

1. subclassing controls in dynamically biult dialog box

2. Modeless dialog box together with modal dialog box

3. activating a button on a dialog box from a dialog box

4. Dialog box in a dialog box

5. transfer data from one dialog box to another dialog box

6. PBM: Message box not displayed after main dialog box is closed in MFC dialog-based app

7. set an arbitrary printer driver in print dialog box without showing the print dialog box

8. how to set an arbitrary printer driver in print dialog box without showing the dialog box

9. Please help me with Combo box subclassing problem

10. List Box subclassing ( and overriding in general ...)

11. Subclassing the standard message box

12. Subclassing combo box


Powered by phpBB® Forum Software