다음 한 개의 C++ 소스파일 만으로 간단한 Visual C++ 2010 용 Win32 응용프로그램을 만든다.
//
// Compile: cl /Zi /nologo /W3 /WX- /O2 /Oi /Oy- /GL /D "WIN32"
// /D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE" /Gm- /EHsc /GS /Gy /fp:precise
// /Zc:wchar_t /Zc:forScope /Gd /analyze- /errorReport:queue ExSdkApp.cpp
// kernel32.lib user32.lib gdi32.lib
//
// Execute: ExSdkApp
//
// See: http://msdn.microsoft.com/en-us/library/vstudio/bb384843(v=vs.100).aspx
// Date: 2013. 10. 10.
#include <windows.h>
#include <stdlib.h>
#include <string.h>
#include <tchar.h>
#include <cmath>
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// 전역 변수(Global variables)
// 주요 창의 클래스 명
static TCHAR szWindowClass[] = _T("win32sample");
// 애플리케이션의 주요 창의 제목
/// static TCHAR szTitle[] = _T("Win32 Guided Tour Application");
static TCHAR szTitle[] = _T("Win32 SDK 간단 예제");
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int iCmdShow)
{
static char szAppName[] = "ExSdk";
HWND hwnd;
MSG msg;
WNDCLASSEX wndclass;
wndclass.cbSize = sizeof (wndclass);
wndclass.style = CS_HREDRAW | CS_VREDRAW;
wndclass.lpfnWndProc = WndProc;
wndclass.cbClsExtra = 0;
wndclass.cbWndExtra = 0;
wndclass.hInstance = hInstance;
wndclass.hIcon = LoadIcon (NULL, IDI_APPLICATION);
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW);
wndclass.hbrBackground = (HBRUSH) GetStockObject(WHITE_BRUSH);
wndclass.lpszMenuName = NULL;
wndclass.lpszClassName = szWindowClass;
wndclass.hIconSm = LoadIcon (NULL, IDI_APPLICATION);
RegisterClassEx( &wndclass );
hwnd = CreateWindow(szWindowClass,
szTitle,,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
500, /// CW_USEDEFAULT,
200, /// CW_USEDEFAULT,
NULL,
NULL,
hInstance,
NULL);
ShowWindow(hwnd, iCmdShow);
UpdateWindow(hwnd);
while (GetMessage(&msg, NULL, 0,0))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
PAINTSTRUCT ps;
wchar_t temp[100];
double x, y;
int ypos;
switch (iMsg)
{
case WM_CREATE:
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
wcscpy_s(temp, 100, L"SDK로 제작한 간단한 Win32 응용프로그램");
TextOut(hdc, 10, 5, temp, _tcslen(temp));
x = 1.2;
y = 5.1;
swprintf(temp, 100, L" 합: %wg + %wg = %wg", x, y, x + y);
ypos = 35;
TextOut(hdc, 15, ypos, temp, _tcslen(temp));
swprintf(temp, 100, L" 차: %wg - %wg = %wg", x, y, x - y);
ypos += 20;
TextOut(hdc, 15, ypos, temp, _tcslen(temp));
swprintf(temp, 100, L" 곱: %wg * %wg = %wg", x, y, x * y);
ypos += 20;
TextOut(hdc, 15, ypos, temp, _tcslen(temp));
if (y != 0.0) {
swprintf(temp, 100, L" 몫: %wg / %wg = %wg", x, y, x / y);
ypos += 20;
TextOut(hdc, 15, ypos, temp, _tcslen(temp));
}
if (x > 0.0) {
swprintf(temp, 100, L"멱승: %wg**%wg = %wg", x, y, pow(x, y));
ypos += 20;
TextOut(hdc, 15, ypos, temp, _tcslen(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;
TextOut(hdc, 15, ypos, temp, _tcslen(temp));
}
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, iMsg, wParam, lParam);
}
* 컴파일하기
명령창에서 아래의 컴파일 명령을 한 줄로 입력한다.
/D "NDEBUG" /D "_WINDOWS" /D "_UNICODE" /D "UNICODE"
/Gm- /EHsc /GS /Gy /fp:precise
/Zc:wchar_t /Zc:forScope /Gd /analyze- /errorReport:queue
ExSdkApp.cpp
kernel32.lib user32.lib gdi32.lib
* 실행 결과
'프로그래밍 > C++' 카테고리의 다른 글
C++ 언어에서 동작하는 쓰레기 수집기(Garbage collector) (0) | 2013.10.20 |
---|---|
명령줄 컴파일러로 컴파일하는 간단한 Visual C++ 2010 용 MFC 응용프로그램 예제 (0) | 2013.10.10 |
Visual C++ 2010 에서 컴파일되는 여러가지 컨솔 Hello 예제 모음 (0) | 2013.10.09 |
C++98 에서와 C++11 에서의 swap 함수 사용법 비교 (0) | 2013.09.30 |
c++0x 의 vector 타입과 for 반복문에 관하여 (0) | 2013.09.27 |