DirectX 11 SDK文档(一)

原文地址:http://blog.csdn.net/cmt100/article/details/6343274


总结

      这是一个初步的教程。我们将通过必要的步骤来创建一个Win32 Application。我们创建一个空白的窗口为DirectX 11做准备。

创建窗口

      每一个窗口应用程序需要至少一个窗口对象。甚至在开始获得DirectX 11的诸多细节之前,我们的Application必须要有一个工作着的窗口。我们有三个事情要做:

      1.注册一个窗口类

         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;

     2.创建一个窗口对象

        g_hInst = hInstance; // 用全局变量来保存应用程序实例句柄

        RECT rc = { 0, 0, 640, 480 };
        AdjustWindowRect( &rc, WS_OVERLAPPEDWINDOW, FALSE );//根据窗口风格,以rc为客户区调整整个窗口大小
        g_hWnd = CreateWindow( szWindowClass, L"Direct3D 11 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 );

     3.检索和调度这个窗口的消息队列的消息

        MSG msg = {0};
        while( GetMessage( &msg, NULL, 0, 0 ) {
                TranslateMessage( &msg );
                DispatchMessage( &msg );

         }

         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;
   }
     对于每个窗口应用程序,这是最少的步骤来创建一个窗口对象。如果我们编译运行这个代码,我们将看到一个空的白色背景的窗口。


你可能感兴趣的:(VC++相关,Direct3D/OpenGL,Windows编程,文档,application,null,callback,工作,up)