Is there any way to find out if a given window in Windows 7/10 is in the "expanding" or "minimizing" state?

The bottom line is that if desktop effects are turned on (Aero in Windows 7), windows have a certain animation when minimized and maximized. However, if you 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 deployment animation ends).

I tried to find an API that would allow to learn about such things, but, unfortunately, I did not find solutions.

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

UPD. Unfortunately, I did not find a complete solution to the original problem. So at the moment I just use workaround - for the necessary time I turn off animation effects (and only them), creating a temporary object that restores 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) }; } } 
  • If this animation interferes this way and if I am not mistaken, then it can be removed, and if it does not interfere and you just need to track this event, then you can optionally “check” the window size. - Duracell
  • @Duracell, yes, I remove the animation, use it as a workaround, but, ideally, the solution should also work with animation. Window size does not help, WinAPI returns the correct (full) window size as soon as the user clicks on the window in the task bar. Now I have to flood the state of windows with a frequency of 60 Hz and do all sorts of hacks with the calculation of the estimated time through a steady clock. But it is more crutches than an elegant solution. - Programmer
  • @Grundy, thanks for the link, I have already tried this approach, it allows you to determine if the animation is on (and \ or disable it), but, unfortunately, it does not give an animation time value if it is enabled. - Programmer

2 answers 2

Most likely, you need to use WM_SIZING message or WM_SIZE message .

WM_SIZING
Sent to a window that the user is resizing. If you want to change the size or position.

WM_SIZE
Sent to a window after size has changed.

Usage example

 LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { // ... case WM_SIZE: { //... } case WM_SIZING: { //... } break; } } 
  • This can be done only for my windows, I can’t catch messages that are sent to other windows that are not mine, unless I install global hooks. The last approach was also tried, but this is “heavy artillery” and creates a lot of complications and problems. In other words, I know that the problem could be solved through global hooks, but this is rather a big hack, which, moreover, adds a lot of problems and affects the entire system in essence. - Programmer

How about GetWindowRect ? Return zero means the window is minimized)

  • five
    and what will return if the window is in the process of expanding? - Grundy
  • Good question, but I, unfortunately, do not know the answer to it. I was hoping that this function would not be used as an “independent unit” - but somehow it would help to solve the problem. Perhaps, if you make a series of calls - it will give something. What do you think? - isnullxbh
  • @Grundy, if the window is in the process of expanding, GetWindowRect () returns the full size of the window as if it had already been expanded. - Programmer
  • So a series of calls will not help) - isnullxbh
  • @isnullxbh, now I do a similar series of hacks, I do a constant poling of the window state and its geometry and consider the timestamps between updates, then compare them with the estimated animation time and thus filter the information, but it consumes more CPU and requires constant polling of the visibility of the window and its geometry. - Programmer