Original Post
When I'm alt tabbing out of my program it will still use 99-100% of the computer's processing power, therefore not really launching any programs before I quit the game and only capable of really doing something on a window which was opened prior to launching my program. I'd like it to use a lot less processing power when it's inactive. Here's the code which gets processed when the game is not the active window.
LRESULT CALLBACK WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
if(msg == WM_SETCURSOR || msg == WM_MOVE) return 0;
else if(msg == WM_DESTROY || (msg == WM_SYSCOMMAND && wParam == SC_CLOSE))
{
PostQuitMessage(0);
isgamerunning = false;
return 0;
}
return DefWindowProc(hWnd, msg, wParam, lParam);
}
do
{
if(PeekMessage(&msg, hWnd, 0, 0, PM_REMOVE))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
game->update_game();
}
while(isgamerunning);
void BoNgame::update_game()
{
HRESULT hr;
hr = MGEgfxref->lpdevice->TestCooperativeLevel();
if(hr != D3D_OK)
{
if(hr == D3DERR_DEVICELOST)
{
if(dolostdevice)
{
MGEinputref->lpkeydevice->Unacquire();
MGEinputref->lpmousedevice->Unacquire();
MGEgfxref->d3dxsprite->OnLostDevice();
MGEgfxref->d3dxline->OnLostDevice();
for(int i = 0; i < 12; ++i) if(MGEgfxref->font) delete MGEgfxref->font;
MGEsoundref->stop(0);
dolostdevice = false;
}
return;
}
//ETC ETC........................
}