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

标签 c# winapi hwnd

我想知道如何在调用 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/

相关文章:

c# - 如何在 Java 中使用 C# 数据集?

c++ - 子对话框 - SetWindowTextA 或 SendMessageA 使程序崩溃 - MFC

c# - 在 C# 中将字符串转换为当前区域性

c++ - 无法注册 hwnd 窗口

c# - 基于模式的更智能的字符串替换

c# - 从后面的 C# 代码打开 HTML 模式弹出窗口

c# - linux dd命令的Windows C#实现

C 编程 HWND

c# - 检测应用程序焦点更改/为 HWND 更改 Hook 某些内容?

c# - 如何将 GUID 值传递到 SqlCommand 对象 SQL INSERT 语句中?