winapi – Is it possible to find out if the window is in the "minimized", "maximized" state?

Question:

Is there any way to find out if a given window is "maximized" or "minimized" in Windows 7/10?

The bottom line is that if desktop effects are enabled (Aero in Windows 7), windows have a certain animation when minimizing and expanding. However, if we click on the minimized window in the task bar, and immediately call IsWindowVisible() on this window, Win32API will tell us that the window is already open, but in fact it will be visible only after N milliseconds (when the expanding animation ends).

I tried to find an API that would let me know about such things, but unfortunately I couldn't find a solution.

PS: I know that you can put global hooks (and write a DLL into which to put handlers ) on such actions , but this is too heavy and inelegant hack.

UPD. Unfortunately, I did not find a complete solution to the original problem. So at the moment I just use workaround – for the required time I turn off the animation effects (and only them), creating a temporary object that restores the animations on the destructor (if they were previously enabled by the user).

pub struct AnimationDisabler {
    info: ANIMATIONINFO,
}

pub fn disable_animation() -> Option<AnimationDisabler> {
    let mut animation_info = ANIMATIONINFO {
        cbSize: mem::size_of::<ANIMATIONINFO>() as UINT,
        iMinAnimate: 0
    };
    unsafe { SystemParametersInfoW(SPI_GETANIMATION,
                                                mem::size_of::<ANIMATIONINFO>() as UINT,
                                                &mut animation_info as LPANIMATIONINFO as LPVOID,
                                                0) };


    // Animation is disabled already
    if animation_info.iMinAnimate == 0 {
        return None
    }

    let mut animation_disabled = ANIMATIONINFO {
        cbSize: mem::size_of::<ANIMATIONINFO>() as UINT,
        iMinAnimate: 0
    };

    unsafe { SystemParametersInfoW(SPI_SETANIMATION,
                                                    mem::size_of::<ANIMATIONINFO>() as UINT,
                                                    &mut animation_disabled as LPANIMATIONINFO as LPVOID,
                                                    SPIF_UPDATEINIFILE | SPIF_SENDCHANGE) };

    return Some(AnimationDisabler { info: animation_info });
}

impl Drop for AnimationDisabler {
    fn drop(&mut self) {
        unsafe { SystemParametersInfoW(SPI_SETANIMATION,
                                                    mem::size_of::<ANIMATIONINFO>() as UINT,
                                                    &mut self.info as LPANIMATIONINFO as LPVOID,
                                                    SPIF_UPDATEINIFILE | SPIF_SENDCHANGE) };
    }
}

Answer:

По всей видимости, Вам нужно использовать WM_SIZING message или WM_SIZE message.

WM_SIZING
Sent to a window that the user is resizing. By processing this message, an application can monitor the size and position of the drag rectangle and, if needed, change its size or position.

WM_SIZE
Sent to a window after its size has changed.

Пример использования

LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    switch (message) 
     {
         // ...
        case WM_SIZE:
            {
                //...
            }
        case WM_SIZING:
            {
                //...
            }
            break;
     }
}
Scroll to Top