c# - HWND API: How to disable window animations when calling ShowWindow(...) -


i know how suppress animations when calling hwnd showwindow() method. here code:

[dllimport("user32.dll")] [return: marshalas(unmanagedtype.bool)] static extern bool showwindow(intptr hwnd, showwindowcommands ncmdshow);  public enum showwindowcommands {     hide = 0,     shownormal = 1,     showminimized = 2,     maximize = 3,     shownoactivate = 4,     show = 5,     minimize = 6,     showminnoactive = 7,     showna = 8,     restore = 9,     showdefault = 10,     forceminimize = 11 }  public static void minimizewindow(intptr hwnd) {     showwindow(hwnd, showwindowcommands.minimize); } 

the problem is, animation executes, , method not return until animation finished.

i tried using dwmsetwindowattribute() method:

[dllimport("dwmapi.dll", preservesig = true)] static extern int dwmsetwindowattribute(intptr hwnd, uint attr, ref int attrvalue, int size);  const uint dwm_transitionsforcedisabled = 3;  public static void setenabled(intptr hwnd, bool enabled) {     int attrval = enabled ? 0 : 1;     dwmsetwindowattribute(hwnd, dwm_transitionsforcedisabled, ref attrval, 4); } 

but animations not suppressed. operating system windows 7, 32-bit.

not best option, can try calling systemparametersinfo() specifying spi_getanimation current setting window animations, , if enabled use spi_setanimation disable them before showing window, restore previous setting. example:

[structlayout(layoutkind.sequential)] public struct animationinfo {   uint cbsize;   int iminanimate; }  [dllimport("user32.dll", setlasterror=true)] static extern bool systemparametersinfo(uint uiaction, uint uiparam, ref animationinfo pvparam, uint fwinini);  const uint spi_getanimation = 72; const uint spi_setanimation = 73;  public static void minimizewindow(intptr hwnd) {     animationinfo anim;     anim.cbsize = marshal.sizeof(anim);     anim.iminanimate = 0;     systemparametersinfo(spi_getanimation, 0, anim, 0);      if (anim.iminanimate != 0)     {         anim.iminanimate = 0;         systemparametersinfo(spi_setanimation, 0, anim, 0);          showwindow(hwnd, showwindowcommands.minimize);          anim.iminanimate = 1;         systemparametersinfo(spi_setanimation, 0, anim, 0);     }     else         showwindow(hwnd, showwindowcommands.minimize); }