一个简单的DDraw应用程序2

//-------------------------------------------------------------------------
// 文件名 : 6_1.cpp
// 创建者 : 方煜宽
// 邮箱 : fangyukuan@gmail.com
// 创建时间 : 2010-12-1 23:37
// 功能描述 : 一个简单的DDraw应用程序
// 注意在工程中把ddraw.lib包含进去
// -------------------------------------------------------------------------
#define INITGUID

#include<windows.h>
#include <ddraw.h>

LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

HWND main_window_handle = NULL; // 主窗口句柄
LPDIRECTDRAW7 lpdd = NULL;   // DDraw 对象

int Game_Init(void *parms = NULL, int num_parms = 0)
{
// 创建ddraw对象
if (FAILED(DirectDrawCreateEx(NULL, (void **)&lpdd, IID_IDirectDraw7, NULL)))
return(0);

// 窗口模式(设置协作级别)
lpdd->SetCooperativeLevel(main_window_handle, DDSCL_NORMAL);
return 1;
}

/////////////////////////////////////////////////////////////
int Game_Shutdown()
{
if (lpdd)
{
lpdd->Release();
lpdd = NULL;
}
return 1;
}

int WINAPI WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nShowCmd)
{
HWND hwnd;
MSG msg;
TCHAR lpszClassName[] = TEXT("kuan");

WNDCLASS wc;
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = ::LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = ::LoadCursor(NULL,IDC_ARROW);
wc.hbrBackground = (HBRUSH)::GetStockObject(BLACK_BRUSH);
wc.lpszMenuName = NULL;
wc.lpszClassName = lpszClassName;

RegisterClass(&wc);

// WS_OVERLAPPEDWINDOW 可以改变窗口大小
// WS_OVERLAPPED 不可以改变窗口大小
// WS_POPUP 全屏
hwnd = CreateWindow(lpszClassName,
TEXT("fangyukuan"),
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
300,80,800,600,
NULL,
NULL,
hInstance,
NULL);

main_window_handle = hwnd;

// ::ShowWindow(hwnd,SW_SHOWNORMAL);
// ::UpdateWindow(hwnd);
// while(::GetMessage(&msg,NULL,0,0))
// {
// ::TranslateMessage(&msg);
// ::DispatchMessage(&msg);
// }

Game_Init();
while(TRUE)
{
if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
if (msg.message == WM_QUIT)
break;
::TranslateMessage(&msg);
::DispatchMessage(&msg);
}
}
Game_Shutdown();
return msg.wParam;
}

LRESULT CALLBACK WndProc(HWND hwnd,
UINT message,
WPARAM wParam,
LPARAM lParam)

{
switch(message)
{
case WM_LBUTTONDOWN:
{
::MessageBeep(0);
}
break;
case WM_DESTROY:
::PostQuitMessage(0);
break;
default:
return ::DefWindowProc(hwnd,message,wParam,lParam);
}
return 0;
}

转自

http://www.cnblogs.com/fangyukuan/archive/2011/05/13/2045951.html

上一篇:HDU 1856 Brave Game(巴什博奕)


下一篇:CNN 文本分类