我想知道如何在调用 HWnd ShowWindow() 方法时抑制动画。这是我的代码:
[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);
}
问题是,动画执行了,直到动画结束方法才返回。
我尝试使用 DwmSetWindowAttribute()方法:
[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);
}
但是动画并没有被抑制。 我的操作系统是 Windows 7,32 位。
最佳答案
https://devblogs.microsoft.com/oldnewthing/20121003-00/?p=6423
BOOL ani = TRUE;
DwmSetWindowAttribute(m_top, DWMWA_TRANSITIONS_FORCEDISABLED, &ani, sizeof(ani));
关于c# - HWND API : How to disable window animations when calling ShowWindow(. ..),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37670655/