Click here to Skip to main content
15,896,201 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 324.9K   3.2K   141  
Classes for building MFC-based user interfaces dynamically, with a focus on minimizing resource usage.
// Filename: ControlWnd.h
// 13-May-2006 nschan Initial revision. 

#ifndef CONTROL_WND_INCLUDED
#define CONTROL_WND_INCLUDED

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include "WndEvent.h"
#include <list>

// Forward class declarations.
class CControlDlg;
class CControlGroup;
class CListWnd;
class CTreeWnd;
class CWndControl;

// CControlWnd class.
class CControlWnd : public CWnd, public IWndEventHandler
{
    DECLARE_DYNCREATE(CControlWnd)

public:
    CControlWnd();
    virtual ~CControlWnd();

    void BuildFromXml(const CString& xmlFile);
    void ClearEventList();

    // IWndEventHandler overrides.
    virtual void HandleWndEvent(const CWndEvent& ev);

protected:
    virtual void PostNcDestroy();

    //{{AFX_MSG(CControlWnd)
    afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg int  OnMouseActivate(CWnd* pDesktopWnd, UINT nHitTest, UINT message);
    afx_msg void OnSetFocus(CWnd* pOldWnd);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    LRESULT OnTreeWndSelectionChange(WPARAM wParam, LPARAM lParam);

private:
    bool CreateTreeWnd();
    bool CreateListWnd();
    bool CreateControlDlg();
    void UpdateControlDlg();

    void SaveFocus();
    void RestoreFocus();

    void DeleteGroups();
    void DeleteControls();

    // Current window with focus.
    HWND m_hWndFocus;

    // Top-level control groups.
    std::list<CControlGroup*> m_topLevelGroupsList;

    // All controls.
    std::list<CWndControl*> m_allControlsList;

    // Tree window.
    CTreeWnd* m_treeWnd;
    int       m_minTreeSize;

    // List window.
    CListWnd* m_listWnd;
    int       m_minListSize;

    // Control dialog.
    CControlDlg* m_controlDlg;
};

#endif // CONTROL_WND_INCLUDED

// 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