8,303
社区成员
发帖
与我相关
我的任务
分享
#include <stdio.h>
#include <windows.h>
#include <d3d8.h>
#define WHITE 0
#define FULLSCREEN 0
int Game_Init(void *parms=NULL);
HWND hwnd_app;
LRESULT CALLBACK WindowProc(HWND hwnd,
UINT msg,
WPARAM wParam,
LPARAM lParam)
{
PAINTSTRUCT ps;
HDC hdc;
switch(msg)
{
case WM_CREATE:
{
return 0;
}break;
case WM_PAINT:
{
hdc=BeginPaint(hwnd,&ps);
EndPaint(hwnd,&ps);
return 0;
}break;
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
}break;
default:break;
}
return(DefWindowProc(hwnd,msg,wParam,lParam));
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nShowCmd)
{
WNDCLASS winclass;
HWND hwnd;
MSG msg;
winclass.style=CS_DBLCLKS|CS_OWNDC|CS_HREDRAW|CS_VREDRAW;
winclass.lpfnWndProc=WindowProc;
winclass.cbClsExtra=NULL;
winclass.cbWndExtra=NULL;
winclass.hInstance=hInstance;
winclass.hIcon=LoadIcon(NULL,IDI_APPLICATION);
winclass.hCursor=LoadCursor(NULL,IDC_ARROW);
winclass.hbrBackground=(HBRUSH)GetStockObject(WHITE);
winclass.lpszClassName="simple";
winclass.lpszMenuName=NULL;
if(!RegisterClass(&winclass))
return 0;
if(!(hwnd=CreateWindow("simple","the simple window",FULLSCREEN?(WS_POPUP|WS_VISIBLE):
(WS_OVERLAPPED | WS_VISIBLE | WS_SYSMENU | WS_CAPTION),
0,0,400,400,
NULL,NULL,
hInstance,
NULL)))
return 0;
hwnd_app=hwnd;
int Game_Init();
while(1)
{
if(PeekMessage(&msg,hwnd,NULL,NULL,PM_REMOVE))
{
if(msg.message==WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
return(msg.wParam);
}
int Game_Init(void *parms)
{
IDirect3D8* lpd3d;
D3DCAPS8 ddcaps;
D3DPRESENT_PARAMETERS d3dpp;
IDirect3DDevice8* lpdevice;
lpd3d=Direct3DCreate8(D3D_SDK_VERSION);
if(FAILED(lpd3d->GetDeviceCaps(D3DADAPTER_DEFAULT,
D3DDEVTYPE_HAL,
&ddcaps)))
return 0;
d3dpp.BackBufferWidth=800;
d3dpp.BackBufferHeight=600;
d3dpp.BackBufferFormat=D3DFMT_A8R8G8B8;
d3dpp.BackBufferCount=1;
d3dpp.MultiSampleType=D3DMULTISAMPLE_NONE;
d3dpp.SwapEffect=D3DSWAPEFFECT_DISCARD;
d3dpp.hDeviceWindow=hwnd_app;
d3dpp.Windowed=true;
d3dpp.EnableAutoDepthStencil=true;
d3dpp.AutoDepthStencilFormat=D3DFMT_D24S8;
d3dpp.Flags=0;
d3dpp.FullScreen_RefreshRateInHz=D3DPRESENT_RATE_DEFAULT;
if(FAILED(lpd3d->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hwnd_app,D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp,&lpdevice)))
return 0;
return 0;
}