How to check if my window is hidden / visible?

If I click the "show desktop" button in Windows7, my program will continue to consider it not minimized, and if I click WIN+Dwhile my program is focused, only then my program will catch this minimize command. How can I check for 100% certainty that my program is visible or not?

Here is my main loop:

while(!done){
    if(PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)){
        if(msg.message == WM_QUIT){
            done = TRUE;
        }else{
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }
    }else if(active){
        render();
    }
}

Edit3: Is that good? It looks like work:

case WM_WINDOWPOSCHANGED:
{
        flags = ((PWINDOWPOS)lParam)->flags;
        if((flags & 0x8000) && (flags & SWP_NOCOPYBITS) && (flags & SWP_FRAMECHANGED)){
            active = !(flags & SWP_NOACTIVATE);
        }
        if((flags & 0x1000) && (flags & 0x0800) && (flags & SWP_NOMOVE) && (flags & SWP_NOSIZE)){
            active = 1;
        }
}
case WM_ACTIVATE:
{
    active = !HIWORD(wParam);
    return 0;
}
+3
source share
5 answers

WM_ACTIVATE , . " ", , , .

, , WM_WINDOWPOSCHANGED. , , , IsIconic IsWindowVisible .

+5

, , :

, , , , , . , , , SO-, GetRandomRgn(), GetClipBox() NULLREGION.

+2

IsWindowVisible , . GetTopWindow , Z.

0

WM_ACTIVATEAPP.

wParam will be false if the window from any other application becomes the focus. This includes clicking the "show desktop" button.

0
source

In Windows 8/10, there is another window visibility flag that is separate from IsWindowVisible. Check the DwmGetWindowAttribute and the DWMWA_CLOAKED attribute.

Additionally, windows can be translucent, and GetLayeredWindowAttributes can tell you what the alpha level of a window is.

0
source

All Articles