int _maxTimes = 0;
Window _window;
public void Flash(int times, double millliseconds, Window window)
{
_timer = new DispatcherTimer();
_maxTimes = times;
_timer.Interval = TimeSpan.FromMilliseconds(millliseconds);
_timer.Tick= OnTick;
_window = window;
_timer.Start();
}
void OnTick(object sender, EventArgs e)
{
if (_count < _maxTimes)
{
Win32.FlashWindow(new WindowInteropHelper(_window).Handle, (_count % 2) == 0);
}
else
{
_timer.Stop();
}
}
}
internal static class Win32
{
[DllImport("user32.dll")]
public static extern bool FlashWindow(IntPtr hwnd, bool bInvert);
}
通过FlashWindowHelper 类可以轻松的使任务栏图标闪动起来:
private void flashTaskbar_Click(object sender, RoutedEventArgs e)
{
FlashWindowHelper helper = new FlashWindowHelper();
helper.Flash(8, 400, Application.Current.MainWindow);
}
闪动效果
出处: http://www.cnblogs.com/gnielee/
推荐阅读
- Thumbnail Windows 7 任务栏开发之缩略图预览
- Overlay Icon Windows 7 任务栏开发之覆盖图标
- 调整Windows7的任务栏预览窗口太小
- Windows 7系统下飞信不能启动怎么办
- 巧设置 让Windows7在睡眠时也能下载
- 轻松修改Windows7登录界面背景图
- 巧设置让Windows 7在睡眠时也能下载
- Windows 7新功能小细节里的大秘密
- Windows 7 SP1 Build 7601.16502截图泄漏
- 用AppLocker给Windows 7加把安全锁