Display new mail icon in Windows taskbar using VBScript

前端 未结 4 651
南方客
南方客 2021-01-05 14:10

I was having the hardest time configuring outlook to show the new mail message icon only when I wanted it to. I have several rules/filters set up that I didn\'t want to sho

4条回答
  •  滥情空心
    2021-01-05 14:53

    First add a reference to Microsoft shell controls and notification, then add a module to your outlook vba project with the following code. It makes available a function to show and hide the tray icon (currently set to c:\temp\msn.ico), which you need modify to show a suitable mail icon.

    ' Add reference to Microsoft shell controls and notification
    
    Public Declare Function Shell_NotifyIconA Lib "shell32.dll" (ByVal dwMessage As Long, lpData As NOTIFYICONDATA) As Long
    Public hWnd As Long
    Private Declare Function GetActiveWindow Lib "user32" () As Long
    
    
    Public Type NOTIFYICONDATA
    cbSize As Long ' Size of the NotifyIconData structure
    hWnd As Long ' Window handle of the window processing the icon events
    uID As Long ' Icon ID (to allow multiple icons per application)
    uFlags As Long ' NIF Flags
    uCallbackMessage As Long ' The message received for the system tray icon if NIF_MESSAGE specified. Can be in the range 0x0400 through 0x7FFF (1024 to 32767)
    hIcon As Long ' The memory location of our icon if NIF_ICON is specifed
    szTip As String * 64 ' Tooltip if NIF_TIP is specified (64 characters max)
    End Type
    
    ' Shell_NotifyIconA() messages
    Public Const NIM_ADD = &H0 ' Add icon to the System Tray
    Public Const NIM_MODIFY = &H1 ' Modify System Tray icon
    Public Const NIM_DELETE = &H2 ' Delete icon from System Tray
    
    ' NotifyIconData Flags
    Public Const NIF_MESSAGE = &H1 ' uCallbackMessage in NOTIFYICONDATA is valid
    Public Const NIF_ICON = &H2 ' hIcon in NOTIFYICONDATA is valid
    Public Const NIF_TIP = &H4 'szTip in NOTIFYICONDATA is valid
    
    Private Sub AddTrayIcon()
    Dim nid As NOTIFYICONDATA
    
    ' nid.cdSize is always Len(nid)
    nid.cbSize = Len(nid)
    ' Parent window - this is the window that will process the icon events
    nid.hWnd = GetActiveWindow()
    ' Icon identifier
    nid.uID = 0
    ' We want to receive messages, show the icon and have a tooltip
    nid.uFlags = NIF_MESSAGE Or NIF_ICON Or NIF_TIP
    ' The message we will receive on an icon event
    nid.uCallbackMessage = 1024
    ' The icon to display
    Dim myPicture As IPictureDisp
    strPath = "c:\temp\msn.ico"
    Set myPicture = LoadPicture(strPath)
    nid.hIcon = myPicture
    ' Our tooltip
    nid.szTip = "Always terminate the tooltip with vbNullChar" & vbNullChar
    
    ' Add the icon to the System Tray
    Shell_NotifyIconA NIM_ADD, nid
    
    
    End Sub
    
    
    
    Private Sub RemoveTrayIcon()
    Dim nid As NOTIFYICONDATA
    
    nid.hWnd = GetActiveWindow()
    nid.cbSize = Len(nid)
    nid.uID = 0 ' The icon identifier we set earlier
    
    ' Delete the icon
    Shell_NotifyIconA NIM_DELETE, nid
    
    End Sub
    

    See here and here for original code.

提交回复
热议问题