다음 한 개의 C++ 소스파일 만으로 간단한 Visual C++ 2010 용 MFC 응용프로그램을 만든다.
//
// Compile: cl /nologo /MD /W3 /EHsc /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yc /FD /c MfcHelloApp.cpp
//
// Link: link /nologo /subsystem:windows /incremental:no /machine:I386 /out:"MfcHelloApp.exe" MfcHelloApp.obj
//
// Execute: MfcHelloApp
//
// See: %VisualStudio2010_HOME%\Samples\Mfc\general\helloapp\helloapp.cpp
// Date: 2013. 10. 10.
#include <afxwin.h>
#include <wchar.h>
#include <cmath>
#ifdef MINIMAL
// Stub out non-critical CRT initialization functions
extern "C" void _setenvp() { }
extern "C" void _setargv() { }
// Define a window class derived from CWnd
class CHelloWindow : public CWnd
{
public:
CHelloWindow()
{
CreateEx(WS_EX_CLIENTEDGE,
AfxRegisterWndClass(0, ::LoadCursor(NULL, IDC_ARROW),
(HBRUSH)(COLOR_WINDOW+1)),
_T("Hello World!"),
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
400, /// CW_USEDEFAULT,
220, /// CW_USEDEFAULT,
NULL,
NULL,
0);
}
};
#else
// Define a window class derived from CFrameWnd
class CHelloWindow : public CFrameWnd
{
public:
CHelloWindow()
{ Create(NULL, _T("MFC, 안녕?"), WS_OVERLAPPEDWINDOW, rectDefault); }
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP();
};
BEGIN_MESSAGE_MAP(CHelloWindow, CFrameWnd)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CHelloWindow::OnPaint() {
CPaintDC dc(this);
CString msg = "간단한 MFC 응용프로그램";
dc.TextOut(10, 5, msg);
wchar_t temp[120];
double x, y;
int xpos, ypos;
x = 1.2;
y = 5.1;
swprintf(temp, 100, L" 합: %wg + %wg = %wg", x, y, x + y);
xpos = 75;
ypos = 40;
dc.TextOut(xpos, ypos, temp);
swprintf(temp, 100, L" 차: %wg - %wg = %wg", x, y, x - y);
ypos += 20;
dc.TextOut(xpos, ypos, temp);
swprintf(temp, 100, L" 곱: %wg * %wg = %wg", x, y, x * y);
ypos += 20;
dc.TextOut(xpos, ypos, temp);
if (y != 0.0) {
swprintf(temp, 100, L" 몫: %wg / %wg = %wg", x, y, x / y);
ypos += 20;
dc.TextOut(xpos, ypos, temp);
}
if (x > 0.0) {
swprintf(temp, 100, L"멱승: %wg**%wg = %wg", x, y, pow(x, y));
ypos += 20;
dc.TextOut(xpos, ypos, temp);
}
if (x > 0.0 && x != 0.0 && y > 0.0) {
swprintf(temp, 100, L"로그: log_%wg( %wg ) = %wg", x, y, log(y)/log(x));
ypos += 20;
dc.TextOut(xpos, ypos, temp);
}
}
#endif
// Define an application class derived from CWinApp
class CHelloApp : public CWinApp
{
public:
virtual BOOL InitInstance()
{
m_pMainWnd = new CHelloWindow();
m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->SetWindowPos(NULL, 0, 0, 400, 220, SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOZORDER);
m_pMainWnd->UpdateWindow();
return TRUE;
}
};
CHelloApp HelloApp; // HelloApp's constructor initializes and runs the app
* 컴파일 및 링크하기
명령창에서 다음 컴파일 명령을 한 줄로 입력한다.
/D "_WINDOWS" /D "_AFXDLL" /D "_MBCS" /Yc /FD /c
MfcHelloApp.cpp
이어서 다음 링크 명령을 한 줄로 입력한다.
/out:"MfcHelloApp.exe" MfcHelloApp.obj
* 실행 결과
'프로그래밍 > C++' 카테고리의 다른 글
Visual C++ 2010 과 SymbolicC++ 를 이용한 간단한 부정적분 계산 (0) | 2014.01.17 |
---|---|
C++ 언어에서 동작하는 쓰레기 수집기(Garbage collector) (0) | 2013.10.20 |
명령줄 컴파일러로 컴파일하는 간단한 Visual C++ 2010 용 Win32 응용프로그램 예제 (0) | 2013.10.10 |
Visual C++ 2010 에서 컴파일되는 여러가지 컨솔 Hello 예제 모음 (0) | 2013.10.09 |
C++98 에서와 C++11 에서의 swap 함수 사용법 비교 (0) | 2013.09.30 |