VB and VBA Users Source Code: Deleting the "New Mail Icon" from outlook
[
Home
|
Contents
|
Search
|
Reply
| Previous | Next ]
VB/VBA Source Code
Deleting the "New Mail Icon" from outlook
By:
Andrew Baker
Email (spam proof):
Email the originator of this post
Date:
Thursday, June 20, 2002
Hits:
922
Category:
Windows API
Article:
The following code removes the new mail icon (an envelope) that outlook places in the system tray when you receive a new mail message. This code would typically be called when the Application.NewMail event fires. eg, Private Sub Application_NewMail() OutlookRemoveMailIcon End Sub Source Code: Option Explicit Private 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 Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Integer, ByVal lParam As Any) As Long Private Declare Function GetClassName Lib "user32" Alias "GetClassNameA" (ByVal hwnd As Long, ByVal lpClassName As String, ByVal nMaxCount 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 FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long 'Purpose : Removes the name mail icon from outlook 'Inputs : [bDontShowAgain] If True the new mail icon won't show again when you receive a new mail message. 'Outputs : Returns True if a Outlook mail icon was deleted 'Author : Andrew Baker 'Date : 13/June/2002 'Notes : Copyright www.vbusers.com 'Revisions : Public Function OutlookRemoveMailIcon(Optional bDontShowAgain As Boolean = False) As Boolean Const WUM_RESETNOTIFICATION As Long = &H407 Const GW_HWNDNEXT As Long = 2, GW_HWNDFIRST = 0 Const NIM_DELETE As Long = &H2 Dim sBuffer As String * 64 Dim lhShellTray As Long Dim lhTrayWindow As Long Dim lhIcon As Long Dim tNotify As NOTIFYICONDATA 'Get the Taskbar handle lhShellTray = FindWindow("Shell_TrayWnd", vbNullString) 'Find the first window on the task bar lhIcon = GetWindow(lhShellTray, GW_HWNDFIRST) Do While lhIcon 'Loop through each window in the task bar, checking the class name Call GetClassName(lhIcon, sBuffer, 64) If Left$(sBuffer, 14) = "rctrl_renwnd32" Then 'Found correct class name, try to remove icon 'Setup a notify icon structure tNotify.cbSize = Len(tNotify) tNotify.hwnd = lhIcon tNotify.uID = 0 'Try to delete the system tray icon If Shell_NotifyIcon(NIM_DELETE, tNotify) Then 'Deleted icon If bDontShowAgain = False Then 'Reset the mail engine (else new mail icons won't appear again) Call SendMessage(lhIcon, WUM_RESETNOTIFICATION, 0&, 0&) End If OutlookRemoveMailIcon = True Exit Do End If End If 'Get the next taskbar window lhIcon = GetWindow(lhIcon, GW_HWNDNEXT) Loop End Function
Terms and Conditions
Support this site
Download a trial version of the Excel Workbook Rebuilder