此文章摘自博客园中
wanglj's blog( 窗体 -窗体 的通知行为[1]:闪动 通知 )
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace 窗体闪动
{
public struct FLASHWINFO
{
public UInt32 cbSize;
public IntPtr hwnd;
public UInt32 dwFlags;
public UInt32 uCount;
public UInt32 dwTimeout;
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
[DllImport("user32.dll")]
static extern bool FlashWindowEx(ref FLASHWINFO pwfi);
[DllImport("user32.dll")]
static extern bool FlashWindow(IntPtr handle, bool invert);
//此处按API中参数dwFlags的取值范围声明常量,方便在使用API时调用,实际应用时可以考虑放到一个专门的文件中
public const UInt32 FLASHW_STOP = 0;
public const UInt32 FLASHW_CAPTION = 1;
public const UInt32 FLASHW_TRAY = 2;
public const UInt32 FLASHW_ALL = 3;
public const UInt32 FLASHW_TIMER = 4;
public const UInt32 FLASHW_TIMERNOFG = 12;
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
//准备参数
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = this.Handle;
fInfo.dwFlags = FLASHW_ALL | FLASHW_TIMERNOFG;//这里是闪动窗标题和任务栏按钮,直到用户激活窗体
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
//调用API
FlashWindowEx(ref fInfo);
}
}
}