rules: implementing mark as read

G

godfather2

I got the code below from Experts-Exchange to mark a message as read
and remove the notification envelope in the system tray (I think it's
used as a custom action) when the message satisfies certain rules.
The problem is, I don't have any idea what
to do with the code!!! I have the development tools (Visual Studio
..NET) and such, but I've never done anything with Outlook so I don't
know how to get this to work. Can anyone help?

Thanks!

Option Explicit

'Required Public constants, types & declares
'for the Shell_Notify API method
Public Const NIM_DELETE As Long = &H2

' Structure needed for Shell_Notify API
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 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 WithEvents olInboxItems As Items

Private Sub Application_Startup()
Dim objNS As NameSpace

Set objNS = Application.GetNamespace("MAPI")

' instantiate objects declared WithEvents
Set olInboxItems = _
objNS.GetDefaultFolder(olFolderInbox).Items

Set objNS = Nothing
End Sub

Private Sub Application_Quit()
' disassociate global objects declared WithEvents
Set olInboxItems = Nothing
End Sub

Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
On Error Resume Next

If Item.Subject = "[Clear Icon Sample]" Then
Item.UnRead = False
Item.Save
Call RemoveNewMailIcon
End If

Set Item = Nothing
End Sub


Private Function RemoveNewMailIcon() As Boolean

Dim hNewMailWnd As Long
Dim pShell_Notify As NOTIFYICONDATA
Dim hResult As Long

' Do not use a vbNullString here
hNewMailWnd = FindWindow("rctrl_renwnd32", "")

If (hNewMailWnd) Then
'setup the Shell_Notify structure
pShell_Notify.cbSize = Len(pShell_Notify)
pShell_Notify.hwnd = hNewMailWnd
pShell_Notify.uID = 0

' Remove it from the system tray and catch result
hResult = Shell_NotifyIcon(NIM_DELETE, pShell_Notify)

If (hResult) Then
RemoveNewMailIcon = True
Else
RemoveNewMailIcon = False
End If
End If

End Function
 

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