I would like to know how to suppress the animations when calling the HWnd ShowWindow() method. Here is my 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, the animation executes, and the method does not return until the animation is finished.
I tried using the 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 the animations were not suppressed. My operating system is Windows 7, 32-bit.