# How to disable present function when window is invisible to user. Win32 & DXGI

When my game window is hidden say by minimising it or hitting Ctrl, Alt, Del. I get the DXGI error:

0x087A0001 : The Present operation was invisible to the user.

I've tried wrapping the present function inside an if statement to check whether the window is visible, this comes from: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-iswindowvisible

And looks like this in my code:

bool Graphics::WindowVisible() const
{
if (IsWindowVisible(hWnd) == TRUE)
{
return true;
}
return false;
}


I've created the function in my window object too, and applied it to my EndFrame() call but this doesn't work either.

The function never seems to return false. Any ideas on the best way forward would be gratefully received. If using a check for visibility isn't on the cards, Is there a way to simply disregard the DXGI error and simply throw the frame away and would that be a good idea.

• During my testing, Ctrl+Alt+Del invokes a loss of focus event, and minimizing/restoring invokes a window resize event with the subevent of restoring (i.e., not minimizing and not maximizing). Are you handling these events? Mine fails because I'm not properly restoring lost resources. – Casey Dec 2 '20 at 23:19
• Might not be the right call, I checked the documentation (docs.microsoft.com/en-us/windows/win32/api/winuser/…) and it states -> Because the return value specifies whether the window has the WS_VISIBLE style, it may be nonzero even if the window is totally obscured by other windows. I also note, this might not tell you if the window is minimised also. Maybe check if it does. in c#, I check the windowstate for Minimised, there maybe a corresponding GDI check. – ErnieDingo Dec 2 '20 at 23:53

if (FAILED(hr = pSwapChain->Present(1u, 0)))