Tutorial 0: Win32 Basics(Directx手册)

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个需要涉及的

  1. 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;
      
  2. 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 );
      
  3. 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.

这是所以应用程序的一些建立窗口对象的步骤,如果我们编译并且运行这些代码, 我们将会看到一个空白白色背景的窗口
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值