API |
MFC |
C++ |
C
Programming Windows with MFC
MFC EditBox Example
#include <afxwin.h>
#define ID_BUTTON 1000
#define ID_STATIC 1001
#define ID_EDIT 1002
class CSimpleApp : public CWinApp
{
public:
BOOL InitInstance();
};
class CMainFrame : public CFrameWnd
{
public:
CMainFrame();
afx_msg void OnButtonClick();
DECLARE_MESSAGE_MAP()
//instantiate child control classes
CEdit wEdit;
CStatic wStatic;
CButton wButton;
};
BOOL CSimpleApp::InitInstance(){
m_pMainWnd = new CMainFrame();
m_pMainWnd->ShowWindow(m_nCmdShow);
return TRUE;
}
CMainFrame::CMainFrame()
{
//create child windows:edit,static and button
Create(NULL, TEXT("Edit box example"), WS_OVERLAPPEDWINDOW ,CRect(25,25,310,255));
wEdit.Create(WS_CHILD | WS_VISIBLE | WS_BORDER , CRect(25,25,250,55), this, ID_EDIT);
wStatic.Create(TEXT(""),WS_CHILD | WS_VISIBLE | WS_BORDER , CRect(25,60,250,90), this, ID_STATIC);
wButton.Create(TEXT("Copy button"),WS_CHILD | WS_VISIBLE | WS_BORDER , CRect(25,95,150,135), this, ID_BUTTON);
}
BEGIN_MESSAGE_MAP(CMainFrame,CFrameWnd)
ON_COMMAND(ID_BUTTON,OnButtonClick)//button click message map
END_MESSAGE_MAP()
CSimpleApp MFCApp1;
//respond to mouse click
afx_msg void CMainFrame::OnButtonClick()
{
CString ebitboxcontents;
wEdit.GetWindowText(ebitboxcontents);
wStatic.SetWindowText(ebitboxcontents);
}
Creating a Simple Window |
Processing Messages |
Device Context |
Working with Graphics |
Mapping Modes |
Text Output |
Working with the Mouse |
Dealing with Keyboard Input |
Drawing Lines and Shapes |
Adding Menus |
Child Windows |
Dialog Windows |
Common Dialog Box |
Working with Bitmaps |
Common Controls |
Toolbars |
Document View Architecture |
Multi Document Interface |
Timers |
MFC Collections Classes