gpt4 book ai didi

c# - 有没有办法以编程方式使控制台窗口在任务栏中闪烁

转载 作者:可可西里 更新时间:2023-11-01 07:42:46 27 4
gpt4 key购买 nike

基本上,我制作的控制台应用程序可以执行一些需要几分钟的任务。我想让它在任务栏中闪烁,以便在它完成任务时通知我。

最佳答案

使用 answer that @Zack postedanother one to find the handle of a console app这是我想出来的,效果很好。

class Program
{
[DllImport("user32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);

[StructLayout(LayoutKind.Sequential)]
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public Int32 dwTimeout;
}

public const UInt32 FLASHW_ALL = 3;

static void Main(string[] args)
{
Console.WriteLine("Flashing NOW");
FlashWindow(Process.GetCurrentProcess().MainWindowHandle);
Console.WriteLine("Press any key to continue");
Console.ReadKey();
}

private static void FlashWindow(IntPtr hWnd)
{
FLASHWINFO fInfo = new FLASHWINFO();

fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = hWnd;
fInfo.dwFlags = FLASHW_ALL;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;

FlashWindowEx(ref fInfo);
}
}

关于c# - 有没有办法以编程方式使控制台窗口在任务栏中闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2923250/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com