|
Public Class FlashWindow
Private Declare Auto Function FlashWindowEx Lib "user32" _
(ByRef FWI As FLASHWINFO) As Boolean
Public Enum FlashWindowMode
FlashTitle = 1
FlashTask = 2
FlashAll = FlashTitle Or FlashTask
End Enum
Private Structure FLASHWINFO
Dim cbSize As Integer
Dim hwnd As IntPtr
Dim dwFlags As Integer
Dim uCount As Integer
Dim dwTimeout As Integer
End Structure
Private mNI As NotifyIcon = Nothing
Private NI1 As Icon = Nothing
Private NI2 As Icon = Nothing
Private mFlash As Boolean = False
Private WithEvents T As New Timer
Private ShowIt As Boolean = False
Public Event FlashStarted()
Public Event FlashStopped()
Public Sub New(Optional ByVal NI As NotifyIcon = Nothing, _
Optional ByVal mFlashNotifyIcon As Boolean = False)
NotifyIcon = NI
mFlash = mFlashNotifyIcon
End Sub
Public Property NotifyIcon() As NotifyIcon
Get
Return mNI
End Get
Set(ByVal value As NotifyIcon)
mNI = value
If mNI Is Nothing Then
NI1 = Nothing
NI2 = Nothing
mFlash = False
Else
NI1 = mNI.Icon
NI2 = Icon.FromHandle(New Bitmap(16, 16).GetHicon)
End If
End Set
End Property
Public Property FlashNotifyIcon() As Boolean
Get
Return mFlash
End Get
Set(ByVal value As Boolean)
mFlash = value
End Set
End Property
Public Sub StartFlash(ByVal Frm As Form, _
ByVal FlashMode As FlashWindowMode, _
Optional ByVal FlashCount As Integer = 100000, _
Optional ByVal Intervall As Integer = 500)
Flash(Frm, FlashMode, FlashCount, Intervall)
RaiseEvent FlashStarted()
If mFlash Then
ShowIt = True
T.Interval = Intervall
T.Start()
End If
End Sub
Public Sub StopFlash(ByVal Frm As Form)
Flash(Frm, 0, 0, 0)
T.Stop()
If mNI IsNot Nothing Then
mNI.Icon = NI1
End If
RaiseEvent FlashStopped()
End Sub
Private Sub Flash(ByVal Frm As Form, _
ByVal FlashMode As FlashWindowMode, _
Optional ByVal FlashCount As Integer = 100000, _
Optional ByVal Intervall As Integer = 500)
Dim FlashInfo As New FLASHWINFO
FlashInfo.cbSize = _
System.Runtime.InteropServices.Marshal.SizeOf(FlashInfo)
FlashInfo.dwFlags = FlashMode
FlashInfo.dwTimeout = Intervall
FlashInfo.hwnd = Frm.Handle
FlashInfo.uCount = FlashCount
FlashWindowEx(FlashInfo)
End Sub
Private Sub T_Tick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles T.Tick
If ShowIt Then
mNI.Icon = NI1
Else
mNI.Icon = NI2
End If
ShowIt = Not ShowIt
End Sub
End Class
Public Class Form1
Private WithEvents cFlash As FlashWindow
Private MeWindowState As System.Windows.Forms.FormWindowState
Private WithEvents Item1 As New ToolStripMenuItem()
Private WithEvents Item2 As New ToolStripMenuItem()
Private Separ As New ToolStripSeparator()
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Item1.Text = "Form1 aktivieren"
Item2.Text = "Job beenden"
With ContextMenuStrip1
.Items.Add(Item1)
.Items.Add(Separ)
.Items.Add(Item2)
End With
With NotifyIcon1
.Icon = SystemIcons.Asterisk
.ContextMenuStrip = ContextMenuStrip1
.BalloonTipText = "Form1 zu FlashWindow"
End With
NotifyIcon1.Icon = SystemIcons.Asterisk
RadioButton1.Text = "Flash Title"
RadioButton2.Text = "Flash Task"
RadioButton3.Text = "Flash All"
CheckBox1.Text = "NotifyIcon zeigen"
CheckBox2.Text = "Flash Icon"
CheckBox1.Checked = True
CheckBox2.Checked = True
Button1.Text = "Start Flash"
Button2.Text = "Stop Flash"
Button3.Text = "Minimize Me"
cFlash = New FlashWindow(NotifyIcon1)
End Sub
Private Sub Form1_Resize(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Resize
If Me.WindowState = FormWindowState.Minimized Then
If NotifyIcon1.Visible Then
Me.Hide()
End If
Else
MeWindowState = Me.WindowState
End If
End Sub
Private Sub Form1_Shown(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Shown
RadioButton3.Checked = True
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
Dim FM As FlashWindow.FlashWindowMode = _
FlashWindow.FlashWindowMode.FlashAll
If RadioButton1.Checked Then
FM = FlashWindow.FlashWindowMode.FlashTitle
ElseIf RadioButton2.Checked Then
FM = FlashWindow.FlashWindowMode.FlashTask
End If
If CheckBox2.Checked Then
cFlash.FlashNotifyIcon = True
End If
cFlash.StartFlash(Me, FM)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click
cFlash.StopFlash(Me)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
Me.WindowState = FormWindowState.Minimized
End Sub
Private Sub CheckBox1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles CheckBox1.CheckedChanged
NotifyIcon1.Visible = CheckBox1.Checked
If CheckBox1.Checked Then
CheckBox2.Enabled = True
Else
CheckBox2.Checked = False
CheckBox2.Enabled = False
End If
End Sub
Private Sub Item1_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Item1.Click
Me.Show()
Me.WindowState = MeWindowState
Me.Activate()
cFlash.StopFlash(Me)
End Sub
Private Sub Item2_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Item2.Click
Me.Close()
End Sub
Private Sub NotifyIcon1_DoubleClick(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles NotifyIcon1.DoubleClick
Me.Show()
Me.WindowState = MeWindowState
Me.Activate()
cFlash.StopFlash(Me)
End Sub
Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged
cFlash.StopFlash(Me)
End Sub
Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged
cFlash.StopFlash(Me)
End Sub
Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged
cFlash.StopFlash(Me)
End Sub
End Class |