#define WIN32_LEAN_AND_MEAN #include long DoPaint( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { PAINTSTRUCT PaintStruct; HDC hDC; hDC = BeginPaint( hWnd, &PaintStruct); // Do Paint stuff vvvvvvv // Done with Paint stuff ^^^^^^^ EndPaint( hWnd, &PaintStruct); return 0; } long CALLBACK WindowProc( HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch( uMessage) { case WM_CREATE: return 0; case WM_PAINT: return DoPaint( hWnd, uMessage, wParam, lParam); case WM_DESTROY: PostQuitMessage(0); return 0; default: return DefWindowProc( hWnd, uMessage, wParam, lParam); } } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { HWND hWnd; MSG msg; WNDCLASSEX wc; static char strAppName[] = "DirectDrawSimple"; wc.cbSize = sizeof( WNDCLASSEX); wc.style = CS_HREDRAW | CS_VREDRAW | CS_OWNDC; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.hbrBackground = (HBRUSH) GetStockObject( DKGRAY_BRUSH); wc.hIcon = LoadIcon( NULL, IDI_APPLICATION); wc.hIconSm = LoadIcon( NULL, IDI_HAND); wc.hCursor = LoadCursor( NULL, IDC_CROSS); wc.lpszMenuName = NULL; wc.lpszClassName = strAppName; RegisterClassEx( &wc); hWnd = CreateWindowEx( NULL, strAppName, strAppName, WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, // x pos CW_USEDEFAULT, // y pos 512, // wide 512, // tall NULL, NULL, // Handle to Menu hInstance, NULL ); ShowWindow( hWnd, nCmdShow); UpdateWindow( hWnd); for(;;) { if ( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE) ) { if ( msg.message == WM_QUIT ) { break; } TranslateMessage( &msg); DispatchMessage( &msg); } else { // Do Idle Stuff Here } } return msg.wParam; }