rendered paste bodyvoid DirectDrawWindow::deinit(){ if(!fullscreen) { if(lpDDSBackBuffer) { lpDDSBackBuffer->Release(); lpDDSBackBuffer=0; } if(lpClipper) { lpClipper->Release(); lpClipper=0; } } if(lpDDSPrimary!=0) { lpDDSPrimary->Release(); lpDDSPrimary=0; } if(lpDirectDraw!=0) { lpDirectDraw->Release(); lpDirectDraw=0; } if(hWnd) { if(!DestroyWindow(hWnd)) { MessageBox(0,"Unable To Destroy Window","Error",MB_ICONERROR); } hWnd=0; } if(!UnregisterClass(title.c_str(),wc.hInstance)) { MessageBox(0,"Unable To Unregister Windowclass","Error",MB_ICONERROR); }}bool DirectDrawWindow::create(int w,int h,int bpp,std::string title,bool fullscreen){ //Set Classmember this->width=w; this->height=h; this->bpp=bpp; this->title=title; this->fullscreen=fullscreen; DDSURFACEDESC2 ddsd; DDSCAPS2 ddscaps; DWORD dwCooperativeFlags; int dwStyleEx; int dwStyle; HRESULT ddrval; //Create Windowclass wc.cbClsExtra=0; wc.cbWndExtra=0; wc.hbrBackground=0; wc.hCursor=LoadCursor(0,IDC_ARROW); wc.hIcon=LoadIcon(0,IDI_APPLICATION); wc.hInstance=GetModuleHandle(0); wc.lpfnWndProc=WndProc_static; wc.lpszClassName=title.c_str(); wc.lpszMenuName=0; wc.style=CS_VREDRAW|CS_HREDRAW; //Register Windowclass if(!RegisterClass(&wc)) { MessageBox(0,"Unable To Register Window","Error",MB_ICONERROR); return false; } //Set Windowstyles for Fullscreenmode or Windowed mode if(!fullscreen) { dwStyle=WS_OVERLAPPEDWINDOW; dwStyleEx=WS_EX_APPWINDOW; } else { dwStyle=WS_POPUP; dwStyleEx=WS_EX_APPWINDOW|WS_EX_TOPMOST; } //Create Window and Check for Success hWnd=CreateWindowEx(dwStyleEx,title.c_str(),title.c_str(),dwStyle,CW_USEDEFAULT,CW_USEDEFAULT,w,h,0,0,wc.hInstance,this); if(hWnd==0) { MessageBox(0,"Unable To Create Window","Error",MB_ICONERROR); deinit(); return false; } ShowWindow(hWnd,SW_SHOW); UpdateWindow(hWnd); //Create DirectDraw7 and check for Success ddrval=DirectDrawCreateEx(0,(void**)&lpDirectDraw,IID_IDirectDraw7,0); if(FAILED(ddrval)) { MessageBox(0,"Unable To Create DirectDraw7","Error",MB_ICONERROR); deinit(); return false; } //Set Coorperativelevel Flags for Fullscreenmode and Window mode application //And Set Coorperativlevel with check for Success if(fullscreen) { dwCooperativeFlags=DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN; } else { dwCooperativeFlags=DDSCL_NORMAL; } ddrval=lpDirectDraw->SetCooperativeLevel(hWnd,dwCooperativeFlags); if(FAILED(ddrval)) { MessageBox(0,"Unable To Set CoorperativeLevel","Error",MB_ICONERROR); deinit(); return false; } //If it is a Fullscreenapp, Set the Displaymode if(fullscreen) { ddrval=lpDirectDraw->SetDisplayMode(w,h,bpp,0,0); if(FAILED(ddrval)) { MessageBox(0,"Unable To Set Display Mode","Error",MB_ICONERROR); deinit(); return false; } } ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2)); ddsd.dwSize=sizeof(DDSURFACEDESC2); //Set Surfacedescription for Fullscreenmode and Windowed mode Applications //And Create the Primary Surface with Success check if(fullscreen) { ddsd.dwFlags=DDSD_CAPS|DDSD_BACKBUFFERCOUNT; ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX; ddsd.dwBackBufferCount=1; } else { ddsd.dwFlags=DDSD_CAPS; ddsd.ddsCaps.dwCaps=DDSCAPS_PRIMARYSURFACE; } ddrval=lpDirectDraw->CreateSurface(&ddsd,&lpDDSPrimary,0); if(FAILED(ddrval)) { MessageBox(0,"Unable To Create Primary Surface","Error",MB_ICONERROR); deinit(); return false; } //Get or Create The Backbuffer for The App if(fullscreen) { ZeroMemory(&ddscaps,sizeof(DDSCAPS2)); ddscaps.dwCaps=DDSCAPS_BACKBUFFER; ddrval=lpDDSPrimary->GetAttachedSurface(&ddscaps,&lpDDSBackBuffer); if(FAILED(ddrval)) { MessageBox(0,"Unable To Get Backbuffer","Error",MB_ICONERROR); deinit(); return false; } } else { //Create A Clipper and check for Success ddrval=lpDirectDraw->CreateClipper(0,&lpClipper,0); if(FAILED(ddrval)) { MessageBox(0,"Unable To Create Clipper","Error",MB_ICONERROR); deinit(); return false; } ddrval=lpClipper->SetHWnd(0,hWnd); if(FAILED(ddrval)) { MessageBox(0,"Unable To Set Window Clipregion","Error",MB_ICONERROR); deinit(); return false; } //Attach Clipper to Primary Surface and check for Success ddrval=lpDDSPrimary->SetClipper(lpClipper); if(FAILED(ddrval)) { MessageBox(0,"Unable To Attach Clipper To Primary Surface","Error",MB_ICONERROR); deinit(); return false; } //Set Surfacedescription for Backbuffer with Success check ZeroMemory(&ddsd,sizeof(DDSURFACEDESC2)); ddsd.dwSize=sizeof(DDSURFACEDESC2); ddsd.dwFlags=DDSD_CAPS|DDSD_HEIGHT|DDSD_WIDTH; ddsd.ddsCaps.dwCaps=DDSCAPS_OFFSCREENPLAIN; ddsd.dwWidth=w; ddsd.dwHeight=h; ddrval=lpDirectDraw->CreateSurface(&ddsd,&lpDDSBackBuffer,0); if(FAILED(ddrval)) { MessageBox(0,"Unable To Create Backbuffer","Error",MB_ICONERROR); deinit(); return false; } } this->active=true; return true;}