Click here to Skip to main content
15,883,558 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 320.5K   3.2K   141  
Classes for building MFC-based user interfaces dynamically, with a focus on minimizing resource usage.
// Filename: ListWnd.h
// 12-Dec-2006 nschan Initial revision. 

#ifndef LIST_WND_INCLUDED
#define LIST_WND_INCLUDED

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

// User message. 
const UINT WM_LISTWND_SELECTION_CHANGE = WM_USER + 0x101;

// CListWnd class.
class CListWnd : public CWnd
{
    DECLARE_DYNCREATE(CListWnd)

public:
    CListWnd();
    virtual ~CListWnd();

    void AddItem(const CString& item);
    void RemoveAllItems();
    int  GetNumItems() const;

    void SetNotifyWnd(CWnd* notifyWnd);

protected:
    //{{AFX_MSG(CListWnd)
    afx_msg int  OnCreate(LPCREATESTRUCT lpCreateStruct);
    afx_msg BOOL OnEraseBkgnd(CDC* pDC);
    afx_msg void OnSize(UINT nType, int cx, int cy);
    //}}AFX_MSG
    DECLARE_MESSAGE_MAP()
    void         OnListBoxSelChanged(NMHDR* pNMHDR, LRESULT* pResult);

private:
    void GetListRect(CRect& rect);

    CListBox  m_listBox;    
    int       m_listMargin;
    CFont     m_listFont;

    CWnd*     m_notifyWnd;
};

#endif // LIST_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