How do I hide a window without blocking on it?
A customer was working on improving their application startup performance. They found that if their application was launched immediately after a fresh boot, the act of dismissing their splash screen was taking over 5% of their boot time. Their code removed the splash screen by calling
ShowWindow(hwndSplash, SW_HIDE). They suspect that the splash screen thread has, for some reason, stopped responding to messages, and while an investigation into that avenue was undertaken, a parallel investigation into reducing the cost of hiding the splash screen was also begun.
One of the things they tried was to remove the
WS_EX_TOOLWINDOW style and call
ITaskbarList::DeleteTab(hwndSplash) but they found that it wasn’t helping.
The reason it wasn’t helping is that editing the window style generates
WM_STYLECHANGED messages to the target window, and now you’re back where you started.
A better way is to use
ShowWindowAsync(hwndSplash, SW_HIDE). The
-Async version of the
ShowWindow function is the
SendNotifyMessage version of
ShowWindow: If the window belongs to another thread group, then it schedules the operation but does not wait for it to complete.