5

Say you have a WS_OVERLAPPEDWINDOW window, and you show it for the first time:

::ShowWindow(hwnd, SW_SHOW);

The window appears with the expected fade-in animation (testing on Windows 10.0.18363).

If you then hide the window:

::ShowWindow(hwnd, SW_HIDE);

and try to re-show it again, with the SW_SHOW call above, it will appear instantly, without the fade-in transition.

The question is: How to make ::ShowWindow() use the fade-in transition when showing the window for the second time?

Note that both the first and subsequent SW_HIDE calls do use the fade-out transition.


There's an unanswered 5-year old question that asks essentially the same for QT, but since this is a Win32 problem, not specific to QT, I've decided to re-ask it in more general terms.

Sea Coast of Tibet
  • 5,055
  • 3
  • 26
  • 37
  • You could use AnimateWindow instead https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-animatewindow – Simon Mourier Dec 19 '20 at 18:27
  • @SimonMourier just tried `::AnimateWindow(hwnd, 200, AW_ACTIVATE | AW_BLEND)` - it does produce *an* animation, but a rather weird one, and entirely different from what the system does when showing the window for the first time. – Sea Coast of Tibet Dec 19 '20 at 18:39
  • Looks like what is needed is a way to re-set the "first time" flag of sorts. I did try the `DWMWA_TRANSITIONS_FORCEDISABLED` attribute for `::DwmSetWindowAttribute()` with `disabled:FALSE`, but to no avail. – Sea Coast of Tibet Dec 19 '20 at 18:41
  • The documentation for [ShowWindow](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-showwindow) points out under which conditions the arguments are ignored. It is quite likely that your first call's `SW_SHOW` argument is simply ignored. You'd have to figure out what value is ultimately passed into the system and replicate that. – IInspectable Dec 20 '20 at 10:46
  • @IInspectable the docs talk about program startup. The window in question is being presented sometime during program execution (think a non-modal About box). – Sea Coast of Tibet Dec 20 '20 at 14:25
  • And yes, I did try the other `SW_SHOW*` flags before posting this question, the results are identical. – Sea Coast of Tibet Dec 20 '20 at 14:35
  • Could you show a mini, complete and reproducible sample and what fade-in animation you expected? – Rita Han Dec 21 '20 at 03:29
  • 1
    Wondering if a solution has been found. I'm also trying to resolve this... – Stefan Koell Nov 25 '21 at 10:45
  • 1
    @StefanKoell I ended up just recreating the window. – Sea Coast of Tibet Dec 02 '21 at 13:22
  • 1
    Is there a way to do this as of 2022? I can't recreate the window – DARKGuy Jan 28 '22 at 07:17

0 Answers0