D3D10 Tutorial 00: Win32 Basics

D3D10 Tutorial 00: Win32 Basics

Reference >
    http://msdn2.microsoft.com/en-us/library/bb172484.aspx


Direct3D 10을 이용한 윈도우 어플리케이션을 만들기 위해서, 우선 모든 Win32 어플리케이션이 그러하듯이 윈도우 객체를 생성해야 합니다. 이번 튜토리얼에서는 Direct3D 10을 본격적으로 다루기에 앞서 먼저 다음 그림과 같이 비어있는 윈도우를 만드는 방법에 대하여 살펴보겠습니다.

이번 튜토리얼의 결과 스크린샷

윈도우를 생성하는 방법은 크게 3단계(윈도우 클래스 등록, 윈도우 객체 생성, 메시지 처리)로 나누어집니다. 우선 프로그램의 시작점인 WinMain함수를 살펴보겠습니다.
WinMain함수에 관하여 자세히 알고 싶으시면
 WinMain : http://winapi.co.kr/win32lec/lec2/lec2-2-1.htm

int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int nCmdShow )
{
    // 1. 윈도우 클래스 등록2. 윈도우 객체 생성
    if( FAILED( InitWindow( hInstance, nCmdShow ) ) )
        return 0;

    // 3. 메시지 루프
    MSG msg = {0};
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }    return (int) msg.wParam;
}

1. 윈도우 클래스 등록

    // Register class
    WNDCLASSEX wcex;
    wcex.cbSize = sizeof(WNDCLASSEX);
    wcex.style          = CS_HREDRAW | CS_VREDRAW;
    wcex.lpfnWndProc    = WndProc;
    wcex.cbClsExtra     = 0;
    wcex.cbWndExtra     = 0;
    wcex.hInstance      = hInstance;
    wcex.hIcon          = LoadIcon(hInstance, (LPCTSTR)IDI_TUTORIAL1);
    wcex.hCursor        = LoadCursor(NULL, IDC_ARROW);
    wcex.hbrBackground  = (HBRUSH)(COLOR_WINDOW+1);
    wcex.lpszMenuName   = NULL;
    wcex.lpszClassName  = szWindowClass;
    wcex.hIconSm        = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_TUTORIAL1);
    if( !RegisterClassEx(&wcex) )
    return FALSE;

윈도우 클래스에 관하여 자세히 알고 싶으시면
 윈도우 클래스 : http://winapi.co.kr/win32lec/lec2/lec2-2-2.htm

2. 윈도우 객체 생성

  // Create window
    g_hInst = hInstance; // Store instance handle in our global variable
    RECT rc = { 0, 0, 640, 480 };
    AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );
    g_hWnd = CreateWindow( szWindowClass, L"Direct3D 10 Tutorial 0: Setting Up Window", WS_OVERLAPPEDWINDOW,
                           CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom - rc.top, NULL, NULL,
                           hInstance, NULL);

    if( !g_hWnd )
        return FALSE;

    ShowWindow( g_hWnd, nCmdShow );

윈도우 객체 생성에 관하여 자세히 알고 싶으시면
 윈도우 객체 생성 : http://winapi.co.kr/win32lec/lec2/lec2-2-2.htm (페이지하단)

3. 메시지를 받아서 처리

   // 메시지 루프
 MSG msg = {0};
    while( GetMessage( &msg, NULL, 0, 0 ) )
    {
        TranslateMessage( &msg );
        DispatchMessage( &msg );
    }

메시지 루프에 관하여 자세히 알고 싶으시면
 메시지루프 : http://winapi.co.kr/win32lec/lec2/lec2-2-3.htm

 LRESULT CALLBACK WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
 {
  PAINTSTRUCT ps;
  HDC hdc;
 
  switch (message)
  {
   case WM_PAINT:
    hdc = BeginPaint(hWnd, &ps);
    EndPaint(hWnd, &ps);
    break;
 
   case WM_DESTROY:
    PostQuitMessage(0);
    break;
 
   default:
    return DefWindowProc(hWnd, message, wParam, lParam);
  }
 
  return 0;
 }

윈도우 프로시져(WndProc)에 관하여 자세히 알고 싶으시면
 윈도우 프로시져 : http://winapi.co.kr/win32lec/lec2/lec2-2-4.htm


위의 3가지 단계는 윈도우 객체를 생성하기 위하여 반드시 필요한 부분입니다. 코드에 관한 자세한 내용을 알고 싶으시면 윈도우 API책을 살펴보시기를 권해드립니다.

See Also >
    D3D10 튜토리얼 : http://hansnara.pe.kr/lifelog/hans/95
     Win32 API : http://winapi.co.kr

- by hans

크리에이티브 커먼즈 라이센스
Creative Commons License

Posted by hans

2007/08/06 21:42 2007/08/06 21:42
, , , , , , ,
Response
A trackback , No Comment
RSS :
http://hansnara.pe.kr/blog/rss/response/96

Trackback URL : http://hansnara.pe.kr/blog/trackback/96

Trackbacks List

  1. Direct3D 10 Tutorial List

    Tracked from hansObsession 2007/08/06 21:44 Delete

    Direct3D 10 Tutorial ListBasic Tutorials >D3D10 Tutorial 00: Win32 Basics ▶ http://hansnara.pe.kr/lifelog/hans/96D3D10 Tutorial 01: Direct3D 10 BasicsD3D10 Tutorial 02: Rendering a TriangleD3D10 Tutorial 03: Shaders and the Effect SystemD3D10 Tutor..

Leave a comment
[Login][OpenID?]