我想知道如何調用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,它看起來像你傳遞數據指針不正確。 –