Flash Taskbar button

Flash Taskbar button when window is inactive or at background. Click button and minimize window to test this sample.

Public Class Form1
    Public Structure FLASHWINFO
        Public cbSize As Int32
        Public hwnd As IntPtr
        Public dwFlags As Int32
        Public uCount As Int32
        Public dwTimeout As Int32
    End Structure

    Private Declare Function FlashWindowEx Lib "user32.dll" (ByRef pfwi As FLASHWINFO) As Int32

    Public Const FLASHW_STOP = 0        ' Stop flashing. The system restores the window to its original state.
    Public Const FLASHW_CAPTION = &H1   ' Flash the window caption.
    Public Const FLASHW_TRAY = &H2      ' Flash the taskbar button.
    Public Const FLASHW_ALL = &H3       ' Flash both the window caption and taskbar button.
    Public Const FLASHW_TIMER = &H4     ' Flash continuously, until the FLASHW_STOP flag is set.
    Public Const FLASHW_TIMERNOFG = &HC ' Flash continuously until the window comes to the foreground.

    Public Sub FlashIcon(ByVal Handle%, ByVal Flags%)
        Dim flash As New FLASHWINFO
        flash.cbSize = System.Runtime.InteropServices.Marshal.SizeOf(flash) '/// size of structure in bytes
        flash.hwnd = Handle '/// Handle to the window to be flashed
        flash.dwFlags = Flags
        flash.dwTimeout = 500 '/// speed of flashes in MilliSeconds ( can be left out )
        FlashWindowEx(flash) '/// flash the window
    End Sub

    Dim WithEvents tmr As New Timer
    Dim count As Integer = 0
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        tmr.Interval = 1000
        tmr.Start()
    End Sub
    Private Sub test(ByVal sender As Object, ByVal e As EventArgs) Handles tmr.Tick
        If count >= 5 Then
            tmr.Stop()
            FlashIcon(MyBase.Handle, FLASHW_TRAY + FLASHW_TIMERNOFG)
        End If
        count += 1
    End Sub
End Class