October 3rd, 2012

How do I suppress the default animation that occurs when I hide or show a window?

A customer wanted to know how they can disable the default fade-in/fade-out animation that occurs when a window is hidden or shown. “I don’t want to use WS_EX_TOOL­WINDOW because that causes my window to disappear from the taskbar. I tried Dwm­Enable­Composition but that affects the entire desktop and is too jarring. We want to suppress the effect because our program replaces one window with another, and we want the operation to be invisible to the user.”

Whoa, heading straight for Dwm­Enable­Composition? That’s using a global solution to a local problem.

To disable the animations on a specific window, use something like this:

HRESULT DisableDwmAnimations(HWND hwnd)
{
    BOOL fDisable = TRUE;
    return DwmSetWindowAttribute(hwnd,
                DWMWA_TRANSITIONS_FORCEDISABLED,
                &fDisable,
                sizeof(fDisable));
}

Re-enabling the animations is left as an exercise for the reader.

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.

0 comments

Discussion are closed.