?? mdlnotify.bas
字號:
Attribute VB_Name = "mdlNotify"
'****************************************************************************
'人人為我,我為人人
'枕善居收藏整理
'發(fā)布日期:2007/03/15
'描 述:網(wǎng)頁搜索音樂播放器 Ver 1.1.0
'網(wǎng) 站:http://www.Mndsoft.com/ (VB6源碼博客)
'網(wǎng) 站:http://www.VbDnet.com/ (VB.NET源碼博客,主要基于.NET2005)
'e-mail :Mndsoft@163.com
'e-mail :Mndsoft@126.com
'OICQ :88382850
' 如果您有新的好的代碼別忘記給枕善居哦!
'****************************************************************************
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
'&&模 塊 名:mdlNotify
'&&創(chuàng) 建 人:加了些東西,可以在explorer崩潰后重新建立
'&&日 期:2007-09-23 14:08:06
'&&描 述:
'&&版 本:V1.0.0
'&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
Option Explicit
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function CallWindowProc Lib "user32.dll" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Public Declare Function SetForegroundWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Const WM_RBUTTONUP = &H205
Private Const WM_LBUTTONUP = &H202
Private Const WM_LBUTTONDBLCLK = &H203
Private Const WM_USER = &H400
Private Const WM_NOTIFYICON = WM_USER + 1 ' 自定義消息
Public Const WM_SIZE As Integer = &H5
Public Const WM_QUERYENDSESSION As Integer = &H11
Public Const SIZE_MINIMIZED As Integer = 1
Public bEnd As Boolean '是否可以關(guān)閉
Private Const GWL_WNDPROC = (-4)
' 關(guān)于氣球提示的自定義消息, 2000下不產(chǎn)生這些消息
Private Const NIN_BALLOONSHOW = (WM_USER + &H2) ' 當(dāng) Balloon Tips 彈出時執(zhí)行
Private Const NIN_BALLOONHIDE = (WM_USER + &H3) ' 當(dāng) Balloon Tips 消失時執(zhí)行(如 SysTrayIcon 被刪除),
' 但指定的 TimeOut 時間到或鼠標(biāo)點擊 Balloon Tips 后的消失不發(fā)送此消息
Private Const NIN_BALLOONUSERCLICK = (WM_USER + &H5) ' 當(dāng)鼠標(biāo)點擊 Balloon Tips 時執(zhí)行。
' 注意:在XP下執(zhí)行時 Balloon Tips 上有個關(guān)閉按鈕,
' 如果鼠標(biāo)點在按鈕上將接收到 NIN_BALLOONTIMEOUT 消息。
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
Private Declare Function RegisterWindowMessage Lib "user32" Alias "RegisterWindowMessageA" (ByVal lpString As String) As Long
Private Type NOTIFYICONDATA
cbSize As Long ' 結(jié)構(gòu)大小(字節(jié))
hwnd As Long ' 處理消息的窗口的句柄
uId As Long ' 唯一的標(biāo)識符
uFlags As Long ' Flags
uCallBackMessage As Long ' 處理消息的窗口接收的消息
hIcon As Long ' 托盤圖標(biāo)句柄
szTip As String * 128 ' Tooltip 提示文本
dwState As Long ' 托盤圖標(biāo)狀態(tài)
dwStateMask As Long ' 狀態(tài)掩碼
szInfo As String * 256 ' 氣球提示文本
uTimeoutOrVersion As Long ' 氣球提示消失時間或版本
' uTimeout - 氣球提示消失時間(單位:ms, 10000 -- 30000)
' uVersion - 版本(0 for V4, 3 for V5)
szInfoTitle As String * 64 ' 氣球提示標(biāo)題
dwInfoFlags As Long ' 氣球提示圖標(biāo)
End Type
' dwState to NOTIFYICONDATA structure
Private Const NIS_HIDDEN = &H1 ' 隱藏圖標(biāo)
Private Const NIS_SHAREDICON = &H2 ' 共享圖標(biāo)
' dwInfoFlags to NOTIFIICONDATA structure
Public Enum InfoFlags
NIIF_NONE = &H0 ' 無圖標(biāo)
NIIF_INFO = &H1 ' "消息"圖標(biāo)
NIIF_WARNING = &H2 ' "警告"圖標(biāo)
NIIF_ERROR = &H3 ' "錯誤"圖標(biāo)
End Enum
' uFlags to NOTIFYICONDATA structure
Private Const NIF_ICON As Long = &H2
Private Const NIF_INFO As Long = &H10
Private Const NIF_MESSAGE As Long = &H1
Private Const NIF_STATE As Long = &H8
Private Const NIF_TIP As Long = &H4
' dwMessage to Shell_NotifyIcon
Private Const NIM_ADD As Long = &H0
Private Const NIM_DELETE As Long = &H2
Private Const NIM_MODIFY As Long = &H1
Private Const NIM_SETFOCUS As Long = &H3
Private Const lngNIM_SETVERSION As Long = &H4
Private IconData As NOTIFYICONDATA
Private lngPreWndProc As Long
Private MsgTaskbarRestart As Long
Private bTaskbarRestart As Boolean
Private Frm As Form
Private MenuL As Menu
Private MenuR As Menu
'*************************************************************************
'**函 數(shù) 名:ShowNotifyIcon
'**輸 入:frForm(Form) (主窗體) -
'** :Optional mnuMenuL(Menu = Nothing)(是否有左菜單,有則寫名字,無則留空) -
'** :Optional mnuMenuR(Menu = Nothing)(是否有右菜單) -
'** :Optional bShowTip(Boolean = False)(是否有氣泡提示,默認(rèn)無) -
'** :Optional strTitle(String = "")(氣泡提示標(biāo)題,默認(rèn)空) -
'** :Optional strInfo(String = "")氣泡提示文字,默認(rèn)空 -
'** :Optional lngType(InfoFlags = NIIF_NONE)氣泡提示圖標(biāo)類型 -
'** :Optional lngTime(Long = 15000) 氣泡提示時間,大于15S -
'**輸 出:無
'**功能描述:
'**全局變量:
'**調(diào)用模塊:
'**作 者:希望
'**日 期:2007-09-23 14:09:22
'**版 本:V1.0.0
'*************************************************************************
Public Sub ShowNotifyIcon(frForm As Form, _
Optional mnuMenuL As Menu = Nothing, _
Optional mnuMenuR As Menu = Nothing, _
Optional bShowTip As Boolean = False, _
Optional strTitle As String = "", _
Optional strInfo As String = "", _
Optional lngType As InfoFlags = NIIF_NONE, _
Optional lngTime As Long = 15000)
strTitle = strTitle & vbNullChar
strInfo = strInfo & vbNullChar
With IconData
.cbSize = Len(IconData)
.hwnd = frForm.hwnd
.uId = 0
.uFlags = IIf(bShowTip = False, NIF_ICON Or NIF_TIP Or NIF_MESSAGE, NIF_TIP Or NIF_ICON Or NIF_MESSAGE Or NIF_INFO Or NIF_STATE)
.uCallBackMessage = WM_NOTIFYICON
.szTip = strTitle
.hIcon = frForm.Icon.Handle
.dwState = 0
.dwStateMask = 0
.szInfo = strInfo
.szInfoTitle = strTitle
.dwInfoFlags = lngType
.uTimeoutOrVersion = lngTime
End With
If lngPreWndProc = 0 Then '沒有初始化
Set Frm = frForm
If Not mnuMenuL Is Nothing Then Set MenuL = mnuMenuL
If Not mnuMenuR Is Nothing Then Set MenuR = mnuMenuR
Shell_NotifyIcon NIM_ADD, IconData
MsgTaskbarRestart = RegisterWindowMessage("TaskbarCreated")
lngPreWndProc = SetWindowLong(Frm.hwnd, GWL_WNDPROC, AddressOf WindowProc)
Else '已初始化
If bTaskbarRestart = True Then
Shell_NotifyIcon NIM_ADD, IconData
bTaskbarRestart = False
Else
Shell_NotifyIcon NIM_MODIFY, IconData
End If
End If
End Sub
Public Sub DelNotifyIcon()
If lngPreWndProc <> 0 Then
Dim IconData As NOTIFYICONDATA
With IconData
.cbSize = Len(IconData)
.hwnd = Frm.hwnd
.uId = 0
.uFlags = NIF_TIP Or NIF_ICON Or NIF_MESSAGE
.uCallBackMessage = WM_NOTIFYICON
.szTip = ""
.hIcon = Frm.Icon.Handle
End With
Shell_NotifyIcon NIM_DELETE, IconData
SetWindowLong Frm.hwnd, GWL_WNDPROC, lngPreWndProc
lngPreWndProc = 0
End If
End Sub
Public Sub SetTrayIcon(picIcon As Picture)
If picIcon.Type <> vbPicTypeIcon Then Exit Sub
With IconData
.hIcon = picIcon.Handle
.uFlags = NIF_ICON
End With
Shell_NotifyIcon NIM_MODIFY, IconData
End Sub
Function WindowProc(ByVal hwnd As Long, ByVal MSG As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
On Error GoTo ERRHAND
If MSG = WM_NOTIFYICON Then
Select Case lParam
Case WM_LBUTTONUP
If Not MenuL Is Nothing Then
SetForegroundWindow Frm.hwnd
Frm.PopupMenu MenuL
End If
Case WM_RBUTTONUP
If Not MenuR Is Nothing Then
SetForegroundWindow Frm.hwnd
Frm.PopupMenu MenuR
End If
Case WM_LBUTTONDBLCLK
Frm.Visible = Not Frm.Visible
If Frm.Visible = True Then
SetForegroundWindow Frm.hwnd
Frm.WindowState = 0
Frm.SetFocus
End If
Case NIN_BALLOONSHOW
'Debug.Print "顯示氣球提示"
Case NIN_BALLOONHIDE
'Debug.Print "刪除托盤圖標(biāo)"
Case NIN_BALLOONTIMEOUT
'Debug.Print "氣球提示消失"
Case NIN_BALLOONUSERCLICK
'Debug.Print "單擊氣球提示"
End Select
ElseIf MSG = WM_SIZE Then
If wParam = SIZE_MINIMIZED Then Frm.Visible = False
ElseIf MSG = WM_QUERYENDSESSION Then '攔截到關(guān)機(jī)信息
bEnd = True
End If
If MSG = MsgTaskbarRestart Then
bTaskbarRestart = True
'ShowNotifyIcon Frm, MenuL, MenuR, True, ".0", "Explorer崩潰,現(xiàn)在重建托盤", NIIF_ERROR, 5000
Exit Function
End If
WindowProc = CallWindowProc(lngPreWndProc, hwnd, MSG, wParam, lParam)
Exit Function
ERRHAND:
MsgBox Err.Description
End Function
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -