|
发表于 2004-3-19 17:15:00
|
显示全部楼层
Re:程序的主流程应该如何写才不让CPU占用率为100%?
WinXP似乎会自动调整CPU使用率.
我这个很奇怪,当运行量很少时,CPU占用少于1%,而FPS=40,
而随着运行量的增多,CPU占用逐渐增多,FPS也上升,目前FPS=72左右,CPU占用80%-90%.
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
MSG msg;
if( !InitWindow( hInst ) ) return 0;
if( !InitDirect2D() ) return 0;
if( !InitData() ) return 0;
while( TRUE )
{
if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
if( msg.message == WM_QUIT )
{
return msg.wParam;
}
if( TranslateAccelerator( g_hWnd, g_hAccel, &msg ) == 0 )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
}
else if( g_bAppActive )
{
if( Render() == 0 )
{
PostMessage( g_hWnd, WM_DESTROY, 0, 0 );
}
}
else
{
WaitMessage();
}
}
return 0;
} |
|