Here are codes showed how to make the application blink in taskbar like MSN Messenger dose.
I have read a discussing thread at stackOverFlow. And then fit it into WPF version. The only different is how to get the handle of the current window. In Windows Forms, you can use this.Handle property to get it. In WPF, you have do it this way: new WindowInteropHelper(this).Handle. Be ware of using System.Runtime.InteropServices and System.Windows.Interop.
There are two buttons on the window. Click Button1 to start flash. Button2 for stopping. The only different is the fInfo.dwFlags property. 3 for starting flash. 0 for stopping.
Edit these codes to fit your scenario and wish you coding fun.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Runtime.InteropServices;
using System.Windows.Interop;
namespace FlashTaskbar {
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window {
[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 UInt32 dwTimeout;
}
public const UInt32 FLASHW_ALL = 3;
public MainWindow() {
InitializeComponent();
}
private void button1_Click(object sender, RoutedEventArgs e) {
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = new WindowInteropHelper(this).Handle;
fInfo.dwFlags = FLASHW_ALL;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
FlashWindowEx(ref fInfo);
}
private void button2_Click(object sender, RoutedEventArgs e) {
FLASHWINFO fInfo = new FLASHWINFO();
fInfo.cbSize = Convert.ToUInt32(Marshal.SizeOf(fInfo));
fInfo.hwnd = new WindowInteropHelper(this).Handle;
fInfo.dwFlags = 0;
fInfo.uCount = UInt32.MaxValue;
fInfo.dwTimeout = 0;
FlashWindowEx(ref fInfo);
}
}
}
1 comment:
Ah, a version of this code that actually works. Thanks so much for sharing
Post a Comment