Systray Mark As Read

G

Guest

When an e-mail is recieved by Outlook there is an indicator flag that is
added to the Systray bar that says there is newly recieved unread mail. I
can mark that particular e-mail in Outlook as read so it doesn't show up in
Bold as Unread. But how do I go about getting rid of that systray icon if
there is no longer any unread mail (after my deletion) in the inbox using
VBA?

Tom
 
A

Andrew Cushen

This was posted awhile ago by George Hester in response
to a similar question:

<<
Subject: Re: How to remove "New Mail" Icon from system
tray
From: "George Hester" <[email protected]> Sent:
1/15/2004 8:39:42 AM




It's not mine:

Option Explicit
Public Const WUM_RESETNOTIFICATION As Long = &H407
Public Const NIM_ADD As Long = &H0
Public Const NIM_MODIFY As Long = &H1
Public Const NIM_DELETE As Long = &H2
Public Const NIF_ICON As Long =
&H2 'adding an icon
Public Const NIF_TIP As Long =
&H4 'adding a tip
Public Const NIF_MESSAGE As Long = &H1 'want
return messages

'Structure needed for Shell_Notify API
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

Public 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

Public Declare Function GetClassName Lib "user32" _
Alias "GetClassNameA" _
(ByVal hwnd As Long, _
ByVal lpClassName As String, _
ByVal nMaxCount As Long) As Long

Public Declare Function GetWindowTextLength Lib "user32" _
Alias "GetWindowTextLengthA" _
(ByVal hwnd As Long) As Long

Public Declare Function GetWindowText Lib "user32" _
Alias "GetWindowTextA" _
(ByVal hwnd As Long, _
ByVal lpString As String, _
ByVal cch As Long) As Long

Public Declare Function EnumWindows Lib "user32" _
(ByVal lpEnumFunc As Long, _
ByVal lParam As Long) As Long

Public Declare Function Shell_NotifyIcon Lib "shell32.dll"
_
Alias "Shell_NotifyIconA" _
(ByVal dwMessage As Long, _
lpData As NOTIFYICONDATA) As Long

Public Declare Function FindWindow Lib "user32" _
Alias "FindWindowA" _
(ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long

Public Function EnumWindowProc(ByVal hwnd As Long, _
ByVal lParam As Long) As
Long
'do stuff here with hwnd
Dim sClass As String
Dim sIDType As String
Dim sTitle As String
Dim hResult As Long
sTitle = GetWindowIdentification(hwnd, sIDType, sClass)
If sTitle = "rctrl_renwnd32" Then
hResult = KillNewMailIcon(hwnd)
End If
If hResult Then
EnumWindowProc = False
'Reset the new mail notification engine
Call SendMessage(hwnd, WUM_RESETNOTIFICATION, 0&,
0&)
Else
EnumWindowProc = True
End If
End Function
Public Function GetWindowIdentification(ByVal hwnd As
Long, _
sIDType As String,
_
sClass As String)
As String
Dim nSize As Long
Dim sTitle As String
'Get the size of the string required
'to hold the window title
nSize = GetWindowTextLength(hwnd)
'If the return is 0, there is no title
If nSize > 0 Then
sTitle = Space$(nSize + 1)
Call GetWindowText(hwnd, sTitle, nSize + 1)
sIDType = "title"
sClass = Space$(64)
Call GetClassName(hwnd, sClass, 64)
Else
'No title, so get the class name instead
sTitle = Space$(64)
Call GetClassName(hwnd, sTitle, 64)
sClass = sTitle
sIDType = "class"
End If
GetWindowIdentification = TrimNullMain(sTitle)
End Function
Public Function KillNewMailIcon(ByVal hwnd As Long) As
Boolean
Dim pShell_Notify As NOTIFYICONDATA
Dim hResult As Long
'Set up the Shell_Notify structure
pShell_Notify.cbSize = Len(pShell_Notify)
pShell_Notify.hwnd = hwnd
pShell_Notify.uID = 0
'Remove it from the system tray and catch result
hResult = Shell_NotifyIcon(NIM_DELETE, pShell_Notify)
If (hResult) Then
KillNewMailIcon = True
Else
KillNewMailIcon = False
End If
End Function
Public Function TrimNullMain(strItem As String) As String
Dim pos As Integer
pos = InStr(strItem, Chr$(0))
If pos Then
TrimNullMain = Left$(strItem, pos - 1)
Else: TrimNullMain = strItem
End If
End Function

Public Sub RemoveNewMailIcon()
EnumWindows AddressOf EnumWindowProc, 0
End Sub
'***
Put this in a module. I put a shortcut to it in my menu.

http://support.microsoft.com/?scid=kb;en-us;292797
 
G

Guest

Thank you Andrew, I had done a search of the headers for Systray and
Read/Unread but didn't find anything. It's a big group to wade through one
on one.

Tom
 
S

Sue Mosher [MVP-Outlook]

Try searching at http://groups.google.com instead of searching just headers.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top