While writing an application to monitor LAN and WAN availability I was forced to use this API to flash the minimized Window icon in the task bar. Note that the NotifyIcon is also useful for notifying the user that an application needs their attention. Here is a class built from a suggestion by a fellow MVP (Rob Teixeira) that does the trick. I encapsulated it in a class to make it easier to integrate into an application. Note that I used an enumeration that the developer using the class will be able to see when coding a call to the FlashWindow method. The code to call the class is shown below.
_______________________________________________________
Imports System.Runtime.InteropServices
Public Class FlashWindow
Public Enum enuFlashOptions As UInteger
FLASHW_ALL = &H3 ' Flash both the window caption and taskbar button.
' This is equivalent to setting the FLASHW_CAPTION | FLASHW_TRAY flags.
FLASHW_CAPTION = &H1 ' Flash the window caption.
FLASHW_STOP = 0 ' Stop flashing. The system restores the window to its original state.
FLASHW_TIMER = &H4 ' Flash continuously, until the FLASHW_STOP flag is set.
FLASHW_TIMERNOFG = &HC ' Flash continuously until the window comes to the foreground.
FLASHW_TRAY = &H2
End Enum
Public Structure FlashWindowInfo
Public cbSize As Integer
Public hwnd As IntPtr
Public dwFlags As UInteger
Public uCount As UInteger
Public dwTimeout As UInteger
End Structure
Declare Function FlashWindowEx Lib "user32.dll" (ByRef pInfo As FlashWindowInfo) As Boolean
Public Sub FlashWindow(ByVal frmForm As Form, _
ByVal FlashWindowInfoFlags As enuFlashOptions, _
Optional ByVal intFlashTimes As UInteger = 5)
If (frmForm.WindowState = FormWindowState.Minimized) Or FlashWindowInfoFlags = enuFlashOptions.FLASHW_STOP Then
Dim info As FlashWindowInfo
With info
.cbSize = Marshal.SizeOf(info)
.dwFlags = FlashWindowInfoFlags ' See enumeration for flag values
.dwTimeout = 0 'Flash rate in ms or default cursor blink rate
.hwnd = frmForm.Handle()
.uCount = intFlashTimes ' Number of times to flash
End With
FlashWindowEx(info)
End If
End Sub
End Class
Yes, this is in VB.NET. Get over it.
______________________________________
The code to invoke the class is as follows:
' Start flashing the program icon (if form is minimized)
Dim fwFlash As New FlashWindow
If Me.WindowState = FormWindowState.Minimized Then
' Flash minimized window
fwFlash.FlashWindow(Me, FlashWindow.enuFlashOptions.FLASHW_ALL, 9999)
End If
hth
See www.hitchhikerguides.net or www.betav.com/blog/billva FMI on my books and speaking tour.