www.pudn.com > QQ2009.rar > mNotifyIcon.bas, change:2009-11-15,size:3725b


Attribute VB_Name = "mNotifyIcon" 
 
Option Explicit 
 
Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long 
Private Declare Function Shell_NotifyIcon Lib "shell32.dll" Alias "Shell_NotifyIconA" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long 
Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, ByVal lpsz As String, ByVal iImageType As Long, ByVal cX As Long, ByVal cY As Long, ByVal fFlags As Long) As Long 
 
Public Type NOTIFYICONDATA 
    cbSize As Long 
    hWnd As Long 
    uID As Long 
    uFlags As Long 
    uCallbackMessage As Long 
    hIcon As Long 
    szTip As String * 64 
End Type 
 
Const WM_USER           As Long = &H400 
Const WM_LBUTTONUP      As Long = &H202 
Const WM_MBUTTONUP      As Long = &H208 
Const WM_RBUTTONUP      As Long = &H205 
Const TRAY_CALLBACK     As Long = (WM_USER + 1001&) 
Const GWL_USERDATA      As Long = (-21) 
Const NIF_ICON          As Long = &H2 
Const NIF_TIP           As Long = &H4 
Const NIM_ADD           As Long = &H0 
Const NIF_MESSAGE       As Long = &H1 
Const NIM_MODIFY        As Long = &H1 
Const NIM_DELETE        As Long = &H2 
Const IMAGE_ICON        As Long = 1 
Const LR_LOADFROMFILE   As Long = &H10 
 
Dim OldWindowProc As Long 
Dim TrayForm As Form 
 
Private TrayData As NOTIFYICONDATA 
 
Public Function WindowProc(ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 
    Select Case Msg 
        Case TRAY_CALLBACK 
            Select Case lParam 
                Case WM_LBUTTONUP 
                    If frmMain.WindowState <> 0 Then Call frmMain.ShowMainForm 
                Case WM_RBUTTONUP 
                    WindowProc = CallWindowProc(OldWindowProc, hWnd, Msg, wParam, lParam) 
                     
                    frmMain.ShowNotifyMenu 
            End Select 
        Case WM_NCACTIVATE 
            If wParam = 0 Then 
                If KB_PassTopMost Then 
                    KB_PassTopMost = False 
                ElseIf CL_PassTopMost Then 
                    CL_PassTopMost = False 
                Else 
                    SetWindowPos frmMain.hWnd, -1, 0, 0, 0, 0, 3 
                End If 
            Else 
                SetWindowPos frmMain.hWnd, -2, 0, 0, 0, 0, 3 
            End If 
    End Select 
     
    WindowProc = CallWindowProc(OldWindowProc, hWnd, Msg, wParam, lParam) 
End Function 
 
Public Sub AddTrayIcon(TrayFrm As Form, IconPath As String) 
    Set TrayForm = TrayFrm 
     
    Dim DeepBitIcon As Long 
    DeepBitIcon = LoadImage(0&, IconPath, IMAGE_ICON, 16, 16, LR_LOADFROMFILE) 
     
    OldWindowProc = SetWindowLong(TrayFrm.hWnd, GWL_WNDPROC, AddressOf WindowProc) 
     
    With TrayData 
        .uID = 0 
        .hWnd = TrayFrm.hWnd 
        .hIcon = DeepBitIcon 
        .uFlags = NIF_ICON + NIF_TIP + NIF_MESSAGE 
        .uCallbackMessage = TRAY_CALLBACK 
        .uFlags = .uFlags Or NIF_MESSAGE 
        .cbSize = Len(TrayData) 
    End With 
     
    Shell_NotifyIcon NIM_ADD, TrayData 
End Sub 
 
Public Sub RemoveTrayIcon() 
    TrayData.uFlags = 0 
     
    Shell_NotifyIcon NIM_DELETE, TrayData 
    SetWindowLong TrayForm.hWnd, GWL_WNDPROC, OldWindowProc 
End Sub 
 
Public Sub SetTrayTip(tip As String) 
    With TrayData 
      .szTip = tip & vbNullChar 
      .uFlags = NIF_ICON Or NIF_MESSAGE Or NIF_TIP 
    End With 
     
    Shell_NotifyIcon NIM_MODIFY, TrayData 
End Sub