DirectX8.1的DirectDraw7研究手记(二) 下

王朝other·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

//下面主要是消息循环,根普通程序不一样

int APIENTRY WinMain(HINSTANCE hInstance,

HINSTANCE hPrevInstance,

LPSTR lpCmdLine,

int nCmdShow)

{

// TODO: Place code here.

MSG msg;

HACCEL hAccelTable;

// Initialize global strings

LoadString(hInstance, IDS_APP_TITLE, szTitle, MAX_LOADSTRING);

LoadString(hInstance, IDC_DIRECTX, szWindowClass, MAX_LOADSTRING);

MyRegisterClass(hInstance);

// Perform application initialization:

if (!InitInstance (hInstance, nCmdShow))

{

return FALSE;

}

hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_DIRECTX);

//初始化DirectDraw环境,并实现DirectDraw功能

if (FAILED(initDirectDraw(hInstance))){

MessageBox ( GetActiveWindow(), "初始化DirectDraw过程中出错!", "Error", MB_OK ) ;

FreeDraw() ;

DestroyWindow ( GetActiveWindow() ) ;

return FALSE ;

}

// Main message loop:

while (1)

{

if(PeekMessage(&msg,NULL,0,0,PM_NOREMOVE))

{

if(!GetMessage(&msg, NULL, 0, 0))

{

return msg.wParam ;

}

if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg))

{

TranslateMessage(&msg);

DispatchMessage(&msg);

}

}

else if(g_bActive)

{

if(FAILED(MainLoop()))

{

FreeDraw();

MessageBox( GetActiveWindow(), TEXT("Displaying the next frame failed. ")

TEXT("The sample will now exit. "), TEXT("DirectDraw Sample"),

MB_ICONERROR | MB_OK );

PostQuitMessage(0);

}

}

else

WaitMessage();

}

return msg.wParam;

}

// FUNCTION: MyRegisterClass()

// PURPOSE: Registers the window class.

ATOM MyRegisterClass(HINSTANCE hInstance)

{

WNDCLASSEX wcex;

wcex.cbSize = sizeof(WNDCLASSEX);

wcex.style = CS_HREDRAW | CS_VREDRAW;

wcex.lpfnWndProc = (WNDPROC)WndProc;

wcex.cbClsExtra = 0;

wcex.cbWndExtra = 0;

wcex.hInstance = hInstance;

wcex.hIcon = LoadIcon(hInstance, (LPCTSTR)IDI_DIRECTX);

wcex.hCursor = LoadCursor(NULL, IDC_ARROW);

wcex.hbrBackground = (HBRUSH )GetStockObject(BLACK_BRUSH);

wcex.lpszMenuName = NULL;

wcex.lpszClassName = szWindowClass;

wcex.hIconSm = LoadIcon(wcex.hInstance, (LPCTSTR)IDI_SMALL);

return RegisterClassEx(&wcex);

}

BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)

{

HWND hWnd;

hInst = hInstance; // Store instance handle in our global variable

hWnd = CreateWindow(szWindowClass, szTitle, WS_POPUP,

CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);

if (!hWnd)

{

return FALSE;

}

ShowWindow(hWnd, nCmdShow);

UpdateWindow(hWnd);

return TRUE;

}

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

{

switch (message)

{

case WM_ACTIVATEAPP:

g_bActive=wParam;

break;

case WM_KEYDOWN:

if(wParam == VK_ESCAPE)

{

PostQuitMessage(0);

return 0;

}

break;

case WM_DESTROY:

FreeDraw();

PostQuitMessage(0);

break;

default:

return DefWindowProc(hWnd, message, wParam, lParam);

}

return 0;

}

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航