//—————————————————————————
#include <windows.h>
#include <ddraw.h>
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#pragma hdrstop
//—————————————————————————
#pragma argsused
#define GAMENAME “DirectDraw 7 窗口示例”
#define ScreenWidth 640
#define ScreenHigh 480
#define ScreenColor 32
#define WINDOWSTYLE WS_VISIBLE|WS_THICKFRAME|WS_SYSMENU|WS_MINIMIZEBOX
IDirectDraw *_DirectDraw=NULL;
IDirectDraw7 *DirectDraw;
IDirectDrawSurface7 *PrimarySurface;
DDSURFACEDESC2 ddsd;
bool InitDirectDraw(HWND hwnd)
{
if(DirectDrawCreate(NULL,&_DirectDraw,NULL)!=DD_OK)return(false);
if(_DirectDraw->QueryInterface(IID_IDirectDraw7,(void **)&DirectDraw)!=DD_OK)
{
_DirectDraw->Release();
return(false);
}
if(DirectDraw->SetCooperativeLevel(hwnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN)!=DD_OK)
{
DirectDraw->Release();
_DirectDraw->Release();
return(false);
}
if(DirectDraw->SetDisplayMode(ScreenWidth,ScreenHigh,ScreenColor,0,0)!=DD_OK)
{
DirectDraw->Release();
_DirectDraw->Release();
return(false);
}
memset(&ddsd,0,sizeof(DDSURFACEDESC2));
ddsd.dwSize =sizeof(DDSURFACEDESC2);
ddsd.dwFlags =DDSD_CAPS;
ddsd.ddsCaps.dwCaps =DDSCAPS_PRIMARYSURFACE;
if(DirectDraw->CreateSurface(&ddsd,&PrimarySurface,NULL)!=DD_OK)
{
DirectDraw->Release();
_DirectDraw->Release();
return(false);
}
return(true);
}
void CloseDirectDraw()
{
PrimarySurface->Release();
DirectDraw->Release();
_DirectDraw->Release();
}
HWND InitWindow(HINSTANCE hinstance)
{
HWND hwnd;
WNDCLASSEX wc;
wc.cbSize=sizeof(WNDCLASSEX);
wc.style=0;
wc.lpfnWndProc=(WNDPROC)DefWindowProc;
wc.cbClsExtra=0;
wc.cbWndExtra=0;
wc.hInstance=hinstance;
wc.hIcon=LoadIcon(NULL,NULL);
wc.hCursor=LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground=(HBRUSH)COLOR_BACKGROUND;
wc.lpszMenuName=0;
wc.lpszClassName=”绝情创作群”;
wc.hIconSm=LoadIcon(hinstance,IDI_APPLICATION);
RegisterClassEx(&wc);
hwnd=CreateWindowEx(NULL,”绝情创作群”,GAMENAME,WINDOWSTYLE,0,0,ScreenWidth,ScreenHigh,0,0,hinstance,0);
ShowWindow(hwnd,SW_SHOWNORMAL);
UpdateWindow(hwnd);
return(hwnd);
}
WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND hwnd;
hwnd=InitWindow(hInstance);
InitDirectDraw(hwnd);
//………….
CloseDirectDraw();
return(0);
}
//—————————————————————————