Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Const NIM_ADD = &H0
Private Const NIM_MODIFY = &H1
Private Const NIM_DELETE = &H2
Private Type NOTIFYICONDATA
cbSize As Long
hwnd As Long
uID As Long
uFlags As Long
uCallbackMessage As Long
hIcon As Long
sTip As String * 64
End Type
Private Const NIF_MESSAGE = &H1
Private Const NIF_ICON = &H2
Private Const NIF_TIP = &H4
Private Const NIF_DOALL = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
Private Const WM_MOUSEMOVE = &H200
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_RBUTTONUP = &H205
Private sysIcon As NOTIFYICONDATA
With sysIcon
.cbSize = LenB(sysIcon)
.hwnd = Me.hwnd
.uID = 1&
.uFlags = NIF_DOALL
.uCallbackMessage = WM_MOUSEMOVE
.hIcon = ImageList1.ListImages(6).Picture
.sTip = value & vbNullChar
End With
Shell_NotifyIcon NIM_ADD, sysIcon '生成图标,可在时间控件中不停调用改变图标
Step-by-Step Example
The following section describes how to flash a form while that form does not have the focus:
Start 16-bit or 32-bit Visual Basic 4.0, or, if it is already running, click New Project on the File menu.
Add a Timer control to the Form1 form.
Copy the following code to the Code window of the Form1 form:
Private Sub Form_GotFocus()
Timer1.Enabled = False
End Sub
Private Sub Form_Load()
Timer1.Interval = GetCaretBlinkTime()
Form2.Show
End Sub
Private Sub Timer1_Timer()
Success = FlashWindow(Form1.hwnd, 1)
End Sub
On the Insert menu, click Form to insert a second form into the project.
Copy the following code to the Code window of the Form2 form:
Private Sub Form_Click()
Form1.Timer1.Enabled = True
End Sub
On the Insert menu, click Module to insert a module into the project.
Copy the following code to the Code window of the Module1 module:
'Depending on what operating system you are using determines the
'correct function declares and variables. This is an example of
'conditional compilation.
#If Win32 Then
Declare Function FlashWindow Lib "user32" ( _
ByVal hwnd As Long, _
ByVal bInvert As Long) As Long
Declare Function GetCaretBlinkTime Lib "user32" () As Long
Dim Success As Long
#Else
Declare Function FlashWindow Lib "User" ( _
ByVal hwnd As Integer, _
ByVal bInvert As Integer) As Integer
Declare Function GetCaretBlinkTime Lib "User" () As Integer
Dim Success As Integer
#End If
On the Run menu, click Start or press the F5 key to start the program. Form1 will be in the foreground with Form2 in the background. Click anywhere in Form2; Form1's Caption Bar will flash until you click Form1.