0

I'm attempting to create a window class that supports fading in and out, even for child windows. Basically it adds the WS_EX_LAYERED style to the window, and then it calls SetLayeredWindowAttributes on a timer, gradually changing the alpha value.

That approach is okay, but of course the fading will become temporarily interrupted if there are higher priority messages that come through the thread's message queue. So, for example, if there's some resize event going on somewhere, the fading will slow or temporarily stop.

I'm wondering if there's a strategy to somehow avoid this. So far my only solution is to create the fadable window on its own thread, so the timer messages don't get interrupted by anything. That solution is feasible, but it does add some additional threading complexity, so I was hoping to avoid it if possible. Thanks for any input.

  • I think you can call `SetLayeredWindowAttributes` from a different thread to the one that created the window, so you could have a thread that just does the fading and leave the window on the thread that created it. Alternatively, if the fading is quick (which it probably should be), just run it on the main thread without dispatching messages and use `QueryPerformanceCounter` for timing. – Jonathan Potter Jul 24 '21 at 22:21
  • @JonathanPotter I have a question about the first approach: even if the timer gets triggered smoothly on the background thread, without interruption, would the call to `SetLayeredWindowAttributes` still potentially run into delays, because it has to interact with a window on the main thread? Or would there be delays from having to post a message to the main thread perhaps? –  Jul 24 '21 at 23:12
  • It depends what form that interaction takes, and to know that you'd need to know how `SetLayeredWindowAttributes` is implemented behind the scenes. I would just try it and see if it helps. – Jonathan Potter Jul 25 '21 at 02:23

0 Answers0