【发布时间】:2009-08-21 15:03:48
【问题描述】:
我偶然发现了下面的这段代码,并尝试在我的 WinForm 应用程序中实现它,以帮助我的用户,因为许多用户并不精通技术。
不幸的是,它什么也没做。它不会产生任何错误或任何东西。它只是不让它闪光。
谁能提供任何见解?我在 Win 7(x64) 和 Win XP (x86) 上都试过了,结果都一样。
我这样称呼它 --> TaskbarFlasher.FlashWindow(this); 来自我的主窗体。
[DllImport("user32.dll")]
private extern static bool FlashWindow(IntPtr hwnd, bool bInvert);
[DllImport("user32.dll")]
private extern static IntPtr GetForegroundWindow();
/// <summary>
/// Notifies the user that the application requests attention
/// by flashing the taskbar if the form is not the current window.
/// </summary>
/// <param name="myForm">The form in question.</param>
public static void FlashWindow(Form myForm)
{
// if the current foreground window isn't this window,
// flash this window in task bar once every 1 second
if (GetForegroundWindow() != myForm.Handle)
{
FlashWindow(myForm.Handle, true);
}
}
【问题讨论】:
-
你为什么要对从你的应用程序点击到他们的邮件客户端的可怜的灵魂释放尖叫闪烁的死亡......或者也许是病毒扫描程序? :D
-
实际上,我需要它来帮助他们看到它已经打开,否则我会让他们尝试运行 DataEntry 应用程序的多个实例...
-
那么你真正想做的是确保应用程序的单个实例,这是另一种问题。而不是通过失去焦点通知来滥用(并真正搞砸)Windows UI 指南。请不要按照你的计划去做。
-
我正在阻止多个实例,但我仍然需要某种方式将它们引导到现有实例。正如我所说,我有一个非常不精通的内部用户群。靠靠; MSN Messenger* 有时不会在任务栏中闪烁吗?我绝对不提倡它,但它似乎满足了我的需求。你们中的任何一个都有其他建议吗?谢谢
-
我有类似的情况:我正在使用互斥锁来查看实例是否唯一,如果不是,我使用 IPC 向现有客户端发送消息以获取它激活并显示自己。
标签: c# winforms interop dllimport taskbar