, LPWSTR cmdLine, int cmdShow ) { UNREFERENCED_PARAMETER( prevInstance ); UNREFERENCED_PARAMETER( cmdLine ); WNDCLASSEX wndClass ={ 0 }; wndClass.cbSize =sizeof( WNDCLASSEX ) ; wndClass.style = CS_HREDRAW| CS_VREDRAW; wndClass.lpfnWndProc =WndProc; wndClass.hInstance =hInstance; wndClass.hCursor =LoadCursor( NULL, IDC_ARROW ); wndClass.hbrBackground= ( HBRUSH )( COLOR_WINDOW + 1 ); wndClass.lpszMenuName= NULL; wndClass.lpszClassName= "DIRECTX11BookWindowClass"; if( !RegisterClassEx(&wndClass ) ) return -1; RECT rc = { 0, 0, 640,480 }; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE ); HWND hwnd =CreateWindowA( "DIRECTX11BookWindowClass", "Blank Win32Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom -rc.top, NULL, NULL, hInstance, NULL ); if( !hwnd ) return -1; ShowWindow( hwnd,cmdShow ); // 初始化 MSG msg = { 0 }; while( msg.message !=WM_QUIT ) { if( PeekMessage(&msg, 0, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { // 进行更新 // 进行绘图操作 } } // 收尾工作 returnstatic_cast( msg.wParam ); } int WINAPI wWinMain( HINSTANCE hInstance, HINSTANCEprevInstance, LPWSTR cmdLine, int cmdShow ) { UNREFERENCED_PARAMETER( prevInstance ); UNREFERENCED_PARAMETER( cmdLine ); WNDCLASSEX wndClass ={ 0 }; wndClass.cbSize =sizeof( WNDCLASSEX ) ; wndClass.style = CS_HREDRAW| CS_VREDRAW; wndClass.lpfnWndProc =WndProc; wndClass.hInstance =hInstance; wndClass.hCursor =LoadCursor( NULL, IDC_ARROW ); wndClass.hbrBackground= ( HBRUSH )( COLOR_WINDOW + 1 ); wndClass.lpszMenuName= NULL; wndClass.lpszClassName= "DIRECTX11BookWindowClass"; if( !RegisterClassEx(&wndClass ) ) return -1; RECT rc = { 0, 0, 640,480 }; AdjustWindowRect(&rc, WS_OVERLAPPEDWINDOW, FALSE ); HWND hwnd =CreateWindowA( "DIRECTX11BookWindowClass", "Blank Win32Window", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, rc.right - rc.left, rc.bottom -rc.top, NULL, NULL, hInstance, NULL ); if( !hwnd ) return -1; ShowWindow( hwnd,cmdShow ); // 初始化 MSG msg = { 0 }; while( msg.message !=WM_QUIT ) { if( PeekMessage(&msg, 0, 0, 0, PM_REMOVE ) ) { TranslateMessage( &msg ); DispatchMessage( &msg ); } else { // 进行更新 // 进行绘图操作 } } // 收尾工作 returnstatic_cast( msg.wParam ); }
其中static_cast<>运算符是用于进行强制类型转换的C++运算。
代码讲解之三:窗口回调过程 这里就直接上代码吧。
代码段4:Blank Win32 Window Demo书写步骤之四:窗口回调过程 [cpp] LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam ) { PAINTSTRUCT paintStruct; HDC hDC; switch( message ) { case WM_PAINT: hDC = BeginPaint( hwnd, &paintStruct ); EndPaint( hwnd, &paintStruct ); break; case WM_DESTROY: PostQuitMessage( 0 ); break; default: return DefWindowProc( hwnd, message, wParam, lParam ); } return 0; } LRESULT CALLBACK WndProc( HWND hwnd, UINT message, WPARAM wParam,LPARAM lParam ) { PAINTSTRUCT paintStruct; HDC hDC; switch( message ) |