现在的游戏大部分都是win32程序,个人也是使用这种结构,下面是基本、最简单的游戏框架 int WINAPI WinMain( IN HINSTANCE hInstance, IN HINSTANCE hPrevInstance, IN LPSTR lpCmdLine, IN int nShowCmd ) { .............................. //上面是一个最基本的win32,这里不贴出代码 BOOL bRet = Startup(hInstance,hWnd,CLIENT_WIDTH,CLIENT_HEIGHT); if (bRet == TRUE) RenderFunc(hWnd); Shutdown(); return 0; } int RenderFunc(HWND hWnd) { static DWORD dwNextFrameTime = 0;//上一帧多少毫秒什么时间? static DWORD dwCurrentTime = 0; MSG msg; for (;;) { if (PeekMessage(&msg,NULL,0,0,PM_REMOVE)) { if (msg.message == WM_QUIT) break; TranslateMessage(&msg); DispatchMessage(&msg); continue; } dwCurrentTime = timeGetTime(); if(dwCurrentTime >= dwNextFrameTime) { dwNextFrameTime = dwCurrentTime + 40; GfxBegin(); Render(hWnd); GfxEnd(); } else Sleep(1); //注意这里最好sleep,否则cpu占用率太高 基本上在50%左右 } return 0; }