给你一个消息处理例子,记得要hook哦 Public Function WindowProc(ByVal hwnd As Long, _ ByVal uMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long 'If the handle returned is to our form, 'call a message handler to deal with 'tray notifications. If it is a general 'system message, pass it on to 'the default window procedure. ' 'If destined for the form and equal to 'our custom hook message (WM_MYHOOK), 'examining lParam reveals the message 'generated, to which we react appropriately. On Error Resume Next
Select Case hwnd
'form-specific handler Case Form1.hwnd
Select Case uMsg 'check uMsg for the application-defined 'identifier (NID.uID) assigned to the 'systray icon in NOTIFYICONDATA (NID).
'WM_MYHOOK was defined as the message sent 'as the .uCallbackMessage member of 'NOTIFYICONDATA the systray icon Case WM_MYHOOK
'lParam is the value of the message 'that generated the tray notification. Select Case lParam Case WM_RBUTTONUP: 'This assures that focus is restored to 'the form when the menu is closed. If the 'form is hidden, it (correctly) has no effect. Call SetForegroundWindow(Form1.hwnd) Form1.PopupMenu Form1.zmnuSysTrayDemo
Case NIN_BALLOONSHOW MsgBox "The balloon tip has just appeared!", _ vbOKOnly Or vbInformation, "VBnet Demo"
Case NIN_BALLOONHIDE MsgBox "The systray icon was removed when" & _ "the balloon tip was displayed", _ vbOKOnly Or vbExclamation, "VBnet Demo"
Case NIN_BALLOONUSERCLICK MsgBox "The user clicked on the balloon tip!", _ vbOKOnly Or vbInformation, "VBnet Demo"
Case NIN_BALLOONTIMEOUT MsgBox "The balloon tip timed-out without " & _ "the user clicking it, or the user " & _ "clicked the balloon tip's close button.", _ vbOKOnly Or vbExclamation, "VBnet Demo"
End Select
'handle any other form messages by 'passing to the default message proc Case Else
或许对你以帮助。
Public Function WindowProc(ByVal hwnd As Long, _
ByVal uMsg As Long, _
ByVal wParam As Long, _
ByVal lParam As Long) As Long 'If the handle returned is to our form,
'call a message handler to deal with
'tray notifications. If it is a general
'system message, pass it on to
'the default window procedure.
'
'If destined for the form and equal to
'our custom hook message (WM_MYHOOK),
'examining lParam reveals the message
'generated, to which we react appropriately.
On Error Resume Next
Select Case hwnd
'form-specific handler
Case Form1.hwnd
Select Case uMsg
'check uMsg for the application-defined
'identifier (NID.uID) assigned to the
'systray icon in NOTIFYICONDATA (NID).
'WM_MYHOOK was defined as the message sent
'as the .uCallbackMessage member of
'NOTIFYICONDATA the systray icon
Case WM_MYHOOK
'lParam is the value of the message
'that generated the tray notification.
Select Case lParam
Case WM_RBUTTONUP: 'This assures that focus is restored to
'the form when the menu is closed. If the
'form is hidden, it (correctly) has no effect.
Call SetForegroundWindow(Form1.hwnd)
Form1.PopupMenu Form1.zmnuSysTrayDemo
Case NIN_BALLOONSHOW
MsgBox "The balloon tip has just appeared!", _
vbOKOnly Or vbInformation, "VBnet Demo"
Case NIN_BALLOONHIDE
MsgBox "The systray icon was removed when" & _
"the balloon tip was displayed", _
vbOKOnly Or vbExclamation, "VBnet Demo"
Case NIN_BALLOONUSERCLICK
MsgBox "The user clicked on the balloon tip!", _
vbOKOnly Or vbInformation, "VBnet Demo"
Case NIN_BALLOONTIMEOUT
MsgBox "The balloon tip timed-out without " & _
"the user clicking it, or the user " & _
"clicked the balloon tip's close button.", _
vbOKOnly Or vbExclamation, "VBnet Demo"
End Select
'handle any other form messages by
'passing to the default message proc
Case Else
WindowProc = CallWindowProc(defWindowProc, _
hwnd, _
uMsg, _
wParam, _
lParam)
Exit Function
End Select
'this takes care of messages when the
'handle specified is not that of the form
Case Else
WindowProc = CallWindowProc(defWindowProc, _
hwnd, _
uMsg, _
wParam, _
lParam)
End Select
End Function