December 28th, 2020

Why is the HSHELL_WINDOWDESTROYED notification raised when a window is hidden, even if it hasn’t been destroyed?

The shell notification HSHELL_WINDOW­CREATED means that there is a new top-level unowned visible window. Conversely, HSHELL_WINDOW­DESTROYED means that a window is no longer a top-level unowned visible window. But these state changes can occur for reasons other than a window being created and destroyed. For example, if a top-level window hides itself, then that will generate a HSHELL_WINDOW­DESTROYED notification, even though no window was destroyed.

Why don’t the names align with what they mean?

These notifications were named while wearing taskbar-colored glasses.

These notifications were created to assist the taskbar in keeping track of the windows in the system. The taskbar shows top-level unowned visible windows, so that’s what the notifications pay attention to. If you hide a top-level unowned window, it hasn’t been destroyed, but it may as well have been destroyed as far as the taskbar is concerned: The window disappears from the taskbar.

Conversely, when the window becomes visible again, it gains a taskbar button. As far as the taskbar is concerned, it may as well have been newly-created.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

2 comments

Discussion is closed. Login to edit/delete existing comments.