我想知道如何调用HWND的ShowWindow()方法时,抑制动画。这是我的代码:HWND API:如何调用的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位。
检查'DwmSetWindowAttribute'的返回值以查看它是否失败,如果是这样,为什么。 –
@Jonathan波特的返回值是零,即操作成功 –
查看答案http://stackoverflow.com/questions/6160118/disable-aero-peek-in-wpf-application,它看起来像你传递数据指针不正确。 –