Summary(总结)
In this preliminary tutorial, we will go through the steps necessary to create a Win32 application. We will be setting up an empty window to prepare for Direct3D 10.
在这章准备教程中,我们将会完成必要的步骤来创建一个win32应用程序,我们将会建立一个空的窗口来准备Direct3D 10.
Source(源程序)
(SDK root)\Samples\C++\Direct3D10\Tutorials\Tutorial00
Setting Up The Window(建立窗口)
Every Windows application requires at least one window object. Before even getting to the Direct3D 10 specifics, our application must have a working window object. Three things are involved:
每一个windows应用程序需要至少一个窗体对象.在我们建立Direct3D细节前,我们的应用程序必须工作在窗体对象中.3个需要涉及的
- Register a window class.注册窗口类
// // 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;
- Create a window object.创建窗口对象
// // 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 );
- Retrieve and dispatch messages for this window.返回和分派窗口消息
// // Main message loop // 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; }
These are the minimum steps required to set up a the window object which is required by every Windows application. If we compile and run this code, we will see a window with a blank white background.
这是所以应用程序的一些建立窗口对象的步骤,如果我们编译并且运行这些代码, 我们将会看到一个空白白色背景的窗口