MFC를 이용한 예제 프로그램

MFC.cpp

~cpp 
#include <afxwin.h>
#include "resource.h"

class CMFCApp : public CWinApp
{
public:
	CMenu m_Menu;

	virtual BOOL InitInstance();

	afx_msg void OnNotSupport();
	afx_msg void OnAppAbout();

	DECLARE_MESSAGE_MAP()
};

BEGIN_MESSAGE_MAP(CMFCApp, CWinApp)
         ON_COMMAND(IDM_NEW, OnNotSupport)
	ON_COMMAND(IDM_OPEN, OnNotSupport)
	ON_COMMAND(IDM_SAVE, OnNotSupport)
	ON_COMMAND(IDM_SAVEAS, OnNotSupport)
	ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
END_MESSAGE_MAP()

CMFCApp theApp;

BOOL CMFCApp::InitInstance()
{
	m_pMainWnd = new CFrameWnd;

	((CFrameWnd *)m_pMainWnd)->Create(NULL, "MFC");
	m_Menu.LoadMenu(IDC_MFC);

	m_pMainWnd->SetMenu(&m_Menu);

	m_pMainWnd->ShowWindow(m_nCmdShow);
	m_pMainWnd->UpdateWindow();

	return TRUE;
}

void CMFCApp::OnNotSupport()
{
	m_pMainWnd->MessageBox("Not Support", "MFC", MB_ICONERROR | MB_OK);
}

void CMFCApp::OnAppAbout()
{
	CDialog aboutDlg(IDD_ABOUTBOX);
	aboutDlg.DoModal();
}

MFC.rc

~cpp 
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"

#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"

/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS

/////////////////////////////////////////////////////////////////////////////
// Korean resources

#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_KOR)
#ifdef _WIN32
LANGUAGE LANG_KOREAN, SUBLANG_DEFAULT
#pragma code_page(949)
#endif //_WIN32

#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//

1 TEXTINCLUDE DISCARDABLE 
BEGIN
    "resource.h"
END

2 TEXTINCLUDE DISCARDABLE 
BEGIN
    "#include ""afxres.h""rn"
    ""
END

3 TEXTINCLUDE DISCARDABLE 
BEGIN
    "rn"
    ""
END

#endif    // APSTUDIO_INVOKED


/////////////////////////////////////////////////////////////////////////////
//
// Menu
//

IDC_MFC MENU DISCARDABLE 
BEGIN
    POPUP "File"
    BEGIN
        MENUITEM "New",                         IDM_NEW
        MENUITEM "Open",                        IDM_OPEN
        MENUITEM "Save",                        IDM_SAVE
        MENUITEM "Save As",                     IDM_SAVEAS
        MENUITEM SEPARATOR
        MENUITEM "Exit",                        ID_APP_EXIT
    END
    POPUP "Help"
    BEGIN
        MENUITEM "About",                       ID_APP_ABOUT
    END
END


/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//

IDD_ABOUTBOX DIALOG DISCARDABLE  0, 0, 182, 63
STYLE DS_MODALFRAME | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "About"
FONT 10, "System"
BEGIN
    DEFPUSHBUTTON   "OK",IDOK,116,38,50,12
    LTEXT           "API Windows Applicationnfor Development in Windows Seminar",
                    IDC_STATIC,16,14,149,17
END


/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//

#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE 
BEGIN
    IDD_ABOUTBOX, DIALOG
    BEGIN
        LEFTMARGIN, 7
        RIGHTMARGIN, 175
        TOPMARGIN, 7
        BOTTOMMARGIN, 56
    END
END
#endif    // APSTUDIO_INVOKED

#endif    // Korean resources
/////////////////////////////////////////////////////////////////////////////



#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//


/////////////////////////////////////////////////////////////////////////////
#endif    // not APSTUDIO_INVOKED

resource.h

~cpp 
//{{NO_DEPENDENCIES}}
// Microsoft Developer Studio generated include file.
// Used by MFC.rc
//
#define IDC_MFC                         101
#define IDD_ABOUTBOX                    102
#define IDM_NEW                         40001
#define IDM_OPEN                        40002
#define IDM_SAVE                        40003
#define IDM_SAVEAS                      40004

// Next default values for new objects
// 
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE        103
#define _APS_NEXT_COMMAND_VALUE         40005
#define _APS_NEXT_CONTROL_VALUE         1000
#define _APS_NEXT_SYMED_VALUE           101
#endif
#endif
Retrieved from http://wiki.zeropage.org/wiki.php/DevelopmentinWindows/MFCExample
last modified 2021-02-07 05:23:08