Progress Bar Windows 7 任务栏开发之进度条( 二 )


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/

推荐阅读