Click here to Skip to main content
15,895,746 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: EditEx.cpp
// 27-May-2006 nschan Initial revision.

#include "stdafx.h"
#include "EditEx.h"

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

BEGIN_MESSAGE_MAP(CEditEx, CEdit)
	//{{AFX_MSG_MAP(CEditEx)
	ON_WM_KEYUP()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

CEditEx::CEditEx()
{
}

CEditEx::~CEditEx()
{
}

BOOL CEditEx::PreCreateWindow(CREATESTRUCT& cs) 
{
	// Add 3D border.
	cs.dwExStyle = WS_EX_CLIENTEDGE;
	
	return CEdit::PreCreateWindow(cs);
}

void CEditEx::OnKeyUp(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	if ( nChar == VK_RETURN )
    {
		int nID = GetDlgCtrlID();
	
		LPARAM lParam = MAKELPARAM(m_hWnd, 0);
		WPARAM wParam = MAKEWPARAM(nID, EN_ENTER_KEY);

		// Notify parent when enter key has been pressed.
		CWnd* pWnd = GetParent();
        if ( pWnd != NULL && ::IsWindow(pWnd->m_hWnd) ) 
            pWnd->PostMessage(WM_COMMAND, wParam, lParam);
	}

	CEdit::OnKeyUp(nChar, nRepCnt, nFlags);
}

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