다음 한 개의 C++ 소스파일 만으로 간단한 Visual C++ 2010 용 Win32 응용프로그램을 만든다.

 

// Filename: ExSdkApp.cpp
//
//  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);
}

 

* 컴파일하기

 명령창에서 아래의 컴파일 명령을 한 줄로 입력한다.

    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

 

* 실행 결과

 

 

 

 

Posted by Scripter
,