1 //basic DirectDraw demo 2 #define INITGUID 3 #include <windows.h> // include important windows stuff 4 #include <windowsx.h> 5 #include <mmsystem.h> 6 #include <iostream> // include important C/C++ stuff 7 #include <conio.h> 8 #include <stdlib.h> 9 #include <malloc.h> 10 #include <memory.h> 11 #include <string.h> 12 #include <stdarg.h> 13 #include <stdio.h> 14 #include <math.h> 15 #include <io.h> 16 #include <fcntl.h> 17 18 #include <ddraw.h> 19 #pragma comment(lib,"ddraw.lib") 20 21 #define WINDOW_CLASS_NAME "winclass" 22 23 #define SCREEN_WIDTH 1280 24 #define SCREEN_HEIGHT 800 25 #define SCREEN_BPP 32 26 #define MAX_COLORS 256 27 28 29 #define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1:0) 30 #define KEY_UP(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 0 : 1) 31 32 #define DD_INIT_STRUCT(ddstruct) { memset(&ddstruct,0,sizeof(ddstruct)); ddstruct.dwSize=sizeof(ddstruct);} 33 34 HWND main_window_handle=NULL; 35 HINSTANCE hinstance_app=NULL; 36 37 LPDIRECTDRAW7 lpdd=NULL; 38 DWORD start_clock_count=0; 39 40 LRESULT CALLBACK WindowProc(HWND hwnd, 41 UINT msg, 42 WPARAM wparam, 43 LPARAM lparam) 44 { 45 PAINTSTRUCT ps; 46 HDC hdc; 47 switch(msg) 48 { 49 case WM_CREATE: 50 { 51 return (0); 52 } 53 break; 54 case WM_PAINT: 55 { 56 hdc=BeginPaint(hwnd,&ps); 57 EndPaint(hwnd,&ps); 58 return (0); 59 } 60 break; 61 case WM_DESTROY: 62 { 63 PostQuitMessage(0); 64 return (0); 65 } 66 break; 67 default :break; 68 } 69 return DefWindowProc(hwnd,msg,wparam,lparam); 70 } 71 72 int Game_Init(void *param=NULL,int num_param=0) 73 { 74 if(FAILED(DirectDrawCreateEx(NULL,(void **)&lpdd,IID_IDirectDraw7,NULL))) 75 { 76 return (0); 77 } 78 lpdd->SetCooperativeLevel(main_window_handle,DDSCL_FULLSCREEN|DDSCL_ALLOWMODEX|DDSCL_EXCLUSIVE|DDSCL_ALLOWREBOOT);//DDSCL_NORMAL); 79 lpdd->SetDisplayMode(SCREEN_WIDTH,SCREEN_HEIGHT,SCREEN_BPP,60,0); 80 return (1); 81 } 82 int Game_Main(void *param=NULL,int num_param=0) 83 { 84 if(KEY_DOWN(VK_ESCAPE)) 85 { 86 SendMessage(main_window_handle,WM_CLOSE,0,0); 87 } 88 return (1); 89 } 90 int Game_ShutDown(void *param=NULL,int num_param=0) 91 { 92 if(lpdd) 93 { 94 lpdd->Release(); 95 lpdd=NULL; 96 } 97 return (1); 98 } 99 int WINAPI WinMain(HINSTANCE hinstance,HINSTANCE hprevinstance,LPSTR lpcmdline,int ncmdshow) 100 { 101 WNDCLASSEX winclass; 102 HWND hwnd; 103 MSG msg; 104 winclass.style=CS_DBLCLKS | CS_OWNDC | CS_HREDRAW | CS_VREDRAW; 105 winclass.cbSize=sizeof(WNDCLASSEX); 106 winclass.cbClsExtra=0; 107 winclass.cbWndExtra=0; 108 winclass.lpfnWndProc=WindowProc; 109 winclass.hInstance=hinstance; 110 winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION); 111 winclass.hCursor=LoadCursor(NULL,IDC_ARROW); 112 winclass.hIconSm=LoadIcon(NULL,IDI_APPLICATION); 113 winclass.hbrBackground=(HBRUSH)GetStockObject(BLACK_BRUSH); 114 winclass.lpszMenuName=NULL; 115 winclass.lpszClassName=WINDOW_CLASS_NAME; 116 117 hinstance_app=hinstance; 118 119 if(!RegisterClassEx(&winclass)) 120 return (0); 121 if(!(hwnd=CreateWindowEx(NULL, 122 WINDOW_CLASS_NAME, 123 "DirectDraw Demo", 124 WS_POPUP | WS_VISIBLE,//WS_OVERLAPPEDWINDOW | WS_VISIBLE, 125 0,0, 126 SCREEN_WIDTH,SCREEN_HEIGHT, 127 NULL, 128 NULL, 129 hinstance,NULL))) 130 return (0); 131 main_window_handle=hwnd; 132 Game_Init(); 133 while(TRUE) 134 { 135 if(PeekMessage(&msg,NULL,0,0,PM_REMOVE)) 136 { 137 if(msg.message==WM_QUIT) 138 { 139 break; 140 } 141 TranslateMessage(&msg); 142 DispatchMessage(&msg); 143 } 144 Game_Main(); 145 } 146 Game_ShutDown(); 147 148 return(msg.wParam); 149 150 }