创建DirectX环境
2007-03-21 21:28:49 来源:WEB开发网核心提示:一、首先创建一个"Hello Word!" Win32 Application程序二、删除WM_PAINT消息中的以下内容// TODO: Add any drawing code here...RECT rt;GetClientRect(hWnd, &rt);DrawText(hdc, szHel
一、首先创建一个"Hello Word!" Win32 Application程序
二、删除WM_PAINT消息中的以下内容
// TODO: Add any drawing code here...
RECT rt;
GetClientRect(hWnd, &rt);
DrawText(hdc, szHello, strlen(szHello), &rt, DT_CENTER);
三、修改函数
ATOM MyRegisterClass(HINSTANCE hInstance)
{
WNDCLASS wc;
//wc.cbSize = sizeof(WNDCLASS);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = (WNDPROC)WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(hInstance, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = NULL;
wc.lpszMenuName = NULL;
wc.lpszClassName = szWindowClass;
return RegisterClass (&wc );
}
四、修改函数
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindowEx(WS_EX_TOPMOST,szWindowClass, szTitle, WS_POPUP,
0, 0,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
return TRUE;
}
五、定义DirectDraw
a) 定义全局变量
LPDIRECTDRAW lpDD;
LPDIRECTDRAWSURFACE lpDDSPrimary;
LPDIRECTDRAWSURFACE lpDDSBack;
b)修改函数
BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
{
HWND hWnd;
hInst = hInstance; // Store instance handle in our global variable
hWnd = CreateWindowEx(WS_EX_TOPMOST,szWindowClass, szTitle, WS_POPUP,
0, 0,GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN), NULL, NULL, hInstance, NULL);
if (!hWnd)
{
return FALSE;
}
ShowWindow(hWnd, nCmdShow);
UpdateWindow(hWnd);
DDSURFACEDESC ddsd;
DDSCAPS ddscaps;
HRESULT ddrval;
HDC hdc;
char buf[256];
ddrval=DirectDrawCreate(NULL,&lpDD,NULL);
if (ddrval==DD_OK)
{
ddrval=lpDD->SetCooperativeLevel (hWnd,DDSCL_EXCLUSIVE|DDSCL_FULLSCREEN);
if (ddrval==DD_OK)
{
ddrval=lpDD->SetDisplayMode (640,480,8);
if (ddrval==DD_OK)
{
ddsd.dwSize =sizeof(ddsd);
ddsd.dwFlags =DDSD_CAPS|DDSD_BACKBUFFERCOUNT;
ddsd.ddsCaps.dwCaps =DDSCAPS_PRIMARYSURFACE|DDSCAPS_FLIP|DDSCAPS_COMPLEX;
ddsd.dwBackBufferCount =1;
ddrval=lpDD->CreateSurface (&ddsd,&lpDDSPrimary,NULL);
if (ddrval==DD_OK)
{
ddscaps.dwCaps =DDSCAPS_BACKBUFFER;
ddrval=lpDDSPrimary->GetAttachedSurface (&ddscaps,&lpDDSBack);
if(ddrval==DD_OK)
{
return TRUE;
}
}
}
}
}
DestroyDirectDrawObjects();
DestroyWindow(hWnd);
return FALSE;
}
c)添加头文件
#include
d)在project|setting|link添加ddraw.lib
e)添加函数声明及函数体
static void DestroyDirectDrawObjects(void);
static void DestroyDirectDrawObjects(void)
{
if(lpDD!=NULL)
{
lpDD->RestoreDisplayMode ();
if(lpDDSPrimary!=NULL)
{
lpDDSPrimary->Release ();
lpDDSPrimary=NULL;
}
lpDD->Release ();
lpDD=NULL;
}
}
六、添加
case WM_KEYDOWN:
switch(wParam)
{
case VK_ESCAPE:
case VK_F12:
DestroyDirectDrawObjects();
PostMessage(hWnd,WM_CLOSE,0,0);
break;
}
break;
- ››创建SQL2005自动备份,定期删除的维护计划
- ››创建动态表单 javascript
- ››创建基于PPTP的站点到站点VPN连接:ISA2006系列之...
- ››创建基于L2TP的站点到站点的VPN连接:ISA2006系列...
- ››创建一个Twisted Reactor TCP服务器
- ››创建Windows Mobile上兼容性好的UI 程序
- ››创建android的Service
- ››创建远古部落环境与原住民角色
- ››创建并扩展Apache Wicket Web应用
- ››创建不在任务条中显示窗口按钮的应用
- ››创建 Android 文件系统(Root file system)
- ››创建 Android 系统步骤简介
更多精彩
赞助商链接