Click here to Skip to main content
15,888,527 members
Articles / Desktop Programming / MFC

Building a Dynamic UI using a CWnd Free Pool

Rate me:
Please Sign up or sign in to vote.
4.84/5 (38 votes)
6 Jan 2007CPOL12 min read 323.4K   3.2K   141  
Classes for building MFC-based user interfaces dynamically, with a focus on minimizing resource usage.
// Filename: ControlDlg.cpp
// 13-May-2006 nschan Initial revision. 

#include "stdafx.h"
#include "ControlDlg.h"
#include "WndContainer.h"
#include "WndControl.h"
#include "Resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

BEGIN_MESSAGE_MAP(CControlDlg, CDialog)
    //{{AFX_MSG_MAP(CControlDlg)
    ON_WM_SIZE()
    //}}AFX_MSG_MAP
END_MESSAGE_MAP()

CControlDlg::CControlDlg(CWnd* pParent)
    : CDialog(IDD_CONTROL_DLG, pParent)
{
    m_wndContainer = new CWndContainer;
    m_wndContainer->AttachWnd(this);
    
    // Create the dialog.
    Create(IDD_CONTROL_DLG, pParent);    
}

CControlDlg::~CControlDlg()
{
    m_wndContainer->DetachWnd();
    delete m_wndContainer;
    m_wndContainer = NULL;    
}

void CControlDlg::PostNcDestroy()
{
    // Delete the C++ instance.
    delete this;    
}

void CControlDlg::AddControl(CWndControl* pControl)
{
    ASSERT( m_wndContainer != NULL );
    m_wndContainer->AddControl(pControl);
}

void CControlDlg::AddControls(std::list<CWndControl*>& controlList)
{
    ASSERT( m_wndContainer != NULL );
    m_wndContainer->AddControls(controlList);
}

void CControlDlg::RemoveControl(CWndControl* pControl)
{
    ASSERT( m_wndContainer != NULL );
    m_wndContainer->RemoveControl(pControl);
}

void CControlDlg::RemoveAllControls()
{
    ASSERT( m_wndContainer != NULL );
    m_wndContainer->RemoveAllControls();    
}

CWndControl* CControlDlg::GetControl(const CString& controlName)
{
    ASSERT( m_wndContainer != NULL );
    return m_wndContainer->GetControl(controlName);
}

void CControlDlg::GetControls(std::list<CWndControl*>& controlList) const
{
    ASSERT( m_wndContainer != NULL );
    m_wndContainer->GetControls(controlList);
}

void CControlDlg::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
    
    //{{AFX_DATA_MAP(CControlDlg)
    //}}AFX_DATA_MAP
}

BOOL CControlDlg::OnInitDialog()
{
    CDialog::OnInitDialog();
    
    return TRUE;  // return TRUE unless you set the focus to a control
                  // EXCEPTION: OCX Property Pages should return FALSE
}

void CControlDlg::OnOK()
{
}

void CControlDlg::OnCancel()
{
}

BOOL CControlDlg::OnCmdMsg(UINT nID, int nCode, void* pExtra, AFX_CMDHANDLERINFO* pHandlerInfo)
{
    if ( m_wndContainer != NULL )
    {
        BOOL isHandled = m_wndContainer->OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
        if ( isHandled )
            return TRUE;
    }
    
    return CDialog::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);    
}

void CControlDlg::OnSize(UINT nType, int cx, int cy)
{
    // Resizing support (none implemented).

    CDialog::OnSize(nType, cx, cy);
}

// END

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Canada Canada
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions