Clear Outlook envelope icon in VSTO?

W

Wei Lu [MSFT]

Hello Harolds,

I would like to know which version of Outlook you want to use and what do
you mean to cleat the Outlook envelope icon?

Did you mean that you do not want to show the envelop icon in the
Notification Area? If so, please use this article to prevent the icon:

1. Within Outlook, click Options from the Tools menu.
2. Select the Preferences tab.
3. Click the E-mail Options button.
4. Click the Advanced E-mail Options button.
5. Remove the check beside the Show an envelop icon in the notification
area.
6. Click OK.

http://www.lockergnome.com/nexus/windows/2006/06/29/prevent-envelope-from-ap
pearing-in-notification-area/

If in the Outlook 2007, you could use the API to hide the envelop:

The Show method of IMsoEnvelope inferface

Description of the mail envelope API in 2007 Office applications
http://support.microsoft.com/kb/926453

Hope this will be helpful!

Sincerely yours,

Wei Lu
Microsoft Online Partner Support

=====================================================

PLEASE NOTE: The partner managed newsgroups are provided to assist with
break/fix
issues and simple how to questions.

We also love to hear your product feedback!

Let us know what you think by posting
- from the web interface: Partner Feedback
- from your newsreader: microsoft.private.directaccess.partnerfeedback.
We look forward to hearing from you!
======================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others
may learn and benefit from this issue.
======================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
======================================================.
 
K

Ken Slovak - [MVP - Outlook]

Do you mean to clear the icon after a new mail delivery using code?

I don't recall any .NET code I've seen for that, and you can't do it using
the Outlook object model, you have to use Win32 API calls. Here's a link to
some code that clears the envelope, you'd have to translate it into .NET
code: http://www.outlookcode.com/d/code/clearenvicon.htm
 
H

Harolds

I am using Outlook 2003.

I want the icon option selected because I want the icon to show up on new
email.

I want to be able to do the same thing that happens to the icon when it is
present and I read or mark an email as read (it goes away until the next new
email), and I want to do this is VSTO.
 
W

Wei Lu [MSFT]

Hello Harolds,

Since you use the Outlook 2003, as Ken said, we could not use the Outlook
object model to control the icon behavior.

We still need to call the Win API in the .Net Code.

My suggestion is that you could follow the article Ken provided to write
your .Net Code. You need to call the same API function to kill the icon.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 
H

Harolds

Does that mean that if I was using Outlook 2007 I can?

If so could you provide an example.
 
W

Wei Lu [MSFT]

Hello Harolds,

The Outlook 2007 did provide a Object Model of the envelop API.

But I did not think you could use it for your purpose. The best approach is
convert the sample code to .NET.

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
H

Harolds

I did that, but was unable to get it to work.

The title "rctrl_renwnd32" was not one of the titles returned by
EnumWindowProc.
 
W

Wei Lu [MSFT]

Hello Harolds,

I found some community member write a C# version of this solution.

http://www.pcreview.co.uk/forums/thread-1854584.php

Here is the code:

//MailManager object in the Add-In
private MailManager _manager= new MailManager();

//applicationObject is Microsoft.Office.Interop.Outlook.Application
applicationObject.NewMail += new
Microsoft.Office.Interop.Outlook.ApplicationEvents
_10_NewMailEventHandler(ap
plicationObject_NewMail);

//Event Handler for Microsoft.Office.Interop.Outlook.Application.NewMa il
event
private void applicationObject_NewMail()
{
_manager.CleanInbox(this.applicationObject);
if(_manager.RemoveIcon)
_manager.RemoveNewMailIcon();
}



//Class to encapsulate Inbox Cleaning
public class MailManager
{
//Function pointer to Callback
private delegate bool EnumWindowProc(IntPtr hwnd, int i);
private bool _removeIcon = false;

[StructLayout(LayoutKind.Sequential)]
internal struct NOTIFYICONDATA
{
public int cbSize;
public IntPtr hwnd;
public int uID;
public int uFlags;
public int uCallbackMessage;
public int hIcon;
public string szTip;
}

[DllImport("user32.dll")]
private static extern int SendMessage(IntPtr hwnd, int msg, int wParam,
int lParam);

[DllImport("user32.dll")]
private static extern int GetClassName(IntPtr hwnd,
[In][Out]StringBuilder
lpClassName, int nMaxCount);

[DllImport("user32.dll")]
private static extern int EnumWindows(EnumWindowProc callback, int
lParam);

[DllImport("shell32.dll")]
private static extern int Shell_NotifyIcon(int dwMessage, ref
NOTIFYICONDATA lpData);

public MailManager()
{
}
//Property if the mail should clear the Icon
public bool RemoveIcon
{
get { return _removeIcon; }
set { _removeIcon = value; }
}

public void ValidateNewMail(object item)
{
//Here is where I deteremine whether to keep to toss item.

Outlook.MailItem mail = item as Outlook.MailItem;
_removeIcon = false;
if (mail != null)
{
if (mail.Subject == "InterScan NT Alert")
{
mail.UnRead = false;
mail.Delete();
_removeIcon = true;
}
else if (mail.Attachments.Count > 0)
{
Outlook.Attachment attachment = mail.Attachments[1] as
Outlook.Attachment;
if (attachment != null)
{
if (attachment.FileName == "InterScan_SafeStamp.txt")
{
mail.UnRead = false;
mail.Delete();
_removeIcon = true;
}
}
}
}
}

//Loops through all items in the Inbox. New Items are Validated.
public void CleanInbox(Outlook.Application outlook)
{
Outlook.NameSpace ns = outlook.GetNamespace("MAPI");
Outlook.MAPIFolder inbox =
ns.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
int i = inbox.Items.Count;
while (i > 0)
{
try
{
Outlook.MailItem mail = inbox.Items as Outlook.MailItem;
if (mail.UnRead)
ValidateNewMail(mail);
}
catch { }
finally
{
i--;
}
}
}

public void RemoveNewMailIcon()
{
EnumWindows(new EnumWindowProc(this.EnumWindowCallback), 0);
}

private bool EnumWindowCallback(IntPtr hwnd, int i)
{
bool bReturn = true;
StringBuilder sb = new StringBuilder(64);
GetClassName(hwnd, sb, 64);
string sClass = sb.ToString();

if (sClass == "rctrl_renwnd32")
{
if (KillNewMailIcon(hwnd))
{
bReturn = false;
SendMessage(hwnd, 1031, 0, 0);
}
}
return bReturn;
}

private bool KillNewMailIcon(IntPtr hwnd)
{
bool bReturn = false;

NOTIFYICONDATA nid = new NOTIFYICONDATA();
nid.cbSize = Marshal.SizeOf(typeof(NOTIFYICONDATA));
nid.hwnd = hwnd;
nid.uID = 0;

int hResult;
hResult = Shell_NotifyIcon(2, ref nid);
if (hResult != 0)
bReturn = true;
return bReturn;
}
}


Hope this will be helpful!

Sincerely,

Wei Lu

Microsoft Online Community Support

==================================================

Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.

==================================================
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
K

Ken Slovak - [MVP - Outlook]

That's always the title for an Outlook window, Explorer or Inspector. If
WordMail is being used then there's also an OpusApp window, but
"rctrl_renwnd32" is always there, even for Outlook 2007.
 
W

Wei Lu [MSFT]

Hi ,

How is everything going? Please feel free to let me know if you need any
assistance.

Sincerely,

Wei Lu
Microsoft Online Community Support

==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.
 

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