Adding Menu (Just) to MailItem - With Exchange multiple menus arecreated

O

orkdev

The following VB6 code adds a Toplevel Menu with a single menu item
to the menu of a MailItem in Outlook. The function of the Addin is to
copy the email body to a database, hence only wanting to add menu to
MailItem menu. It also creates a toolbar with a single button.

"Vision Tools"
-- "Enter email into Vision Patient Record"

The menu is created each time a new MailItem inspector is created (ie
Mail Item opened)
It is destroyed when the MailItem is closed

No problems with standalone Outlook 2003
The menu appears and functions correctly whenever a Mail Item is
opened including a new mail item

The problem occurs when Outlook 2003 is configured to work with *MS
Exchange*
Opening a received email - no problems
However when a New Mail is opened, the new menu appears multiple times
in the Mail Window eventually resulting in a ~~ error message. The
function of the Addin subsequently fails.

Checking for prior existence of menu before attempting to create the
menu makes no difference.

Any thoughts on where I am going astray or pointers to an alternative
approach gratefully received

TIA

Peter

####################################################
Public oMenuBar As Office.CommandBar
Public oMyControl As Office.CommandBarControl
Public WithEvents oMyCB As Office.CommandBarButton


Public oVisionToolBar As Office.CommandBar
Public WithEvents oMyCB2 As Office.CommandBarButton


Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
Dim objItem As Object
'On Error Resume Next
Set m_olMailItem = Nothing
Set objInsp = Inspector
Set objItem = objInsp.CurrentItem
Select Case objItem.Class
Case olMail
Set m_olMailItem = objItem
customiseOLMenu Inspector
Case Else
'
End Select
End Sub

Private Sub objInsp_Close()
'On Error Resume Next
oVisionToolBar.Delete
oMyControl.Delete
m_olApp.ActiveInspector.CommandBars.ActiveMenuBar.Reset
If m_olApp.ActiveExplorer Is Nothing And _
m_olApp.Inspectors.Count <= 1 Then
UnInitHandler
End If
End Sub


Private Sub customiseOLMenu(olIsp As Outlook.Inspector)
' Customize the Outlook Menu structure and toolbar.
Set oMenuBar = olIsp.CommandBars.ActiveMenuBar
Set oMyControl = oMenuBar.Controls.Add(msoControlPopup, , , 7,
True)
oMyControl.Caption = "Vision Tools"
Set oMyCB = oMyControl.Controls.Add( _
Type:=msoControlButton, Temporary:=True, Before:=1)
With oMyCB
.Caption = "Enter email into Vision Patient Record"
.Enabled = IsVisionRunning
End With


Set oVisionToolBar = olIsp.CommandBars.Add("Vision Tools", 1, ,
True)
With oVisionToolBar
.Visible = True
Set oMyCB2 = .Controls.Add(msoControlButton, , , , True)
End With


With oMyCB
.Caption = "Enter email into Vision Patient Record"
.DescriptionText = "Enter email into Vision Patient Record"
.Style = msoButtonIconAndCaption
.Picture = LoadResPicture(103, vbResBitmap)
End With


With oMyCB2
.Caption = "Enter email into Vision Patient Record"
.DescriptionText = "Enter email into Vision Patient Record"
.Style = msoButtonIcon
.Picture = LoadResPicture(103, vbResBitmap)
End With


With oVisionToolBar
.Protection = msoBarNoCustomize


End With


End Sub
 
K

Ken Slovak - [MVP - Outlook]

There should be no difference at all whether or not Exchange is being used
when you add UI to an open mail Inspector. Are you sure the difference isn't
WordMail or not being used?

You say multiple instances of your UI are there. Are you only creating it on
an Inspector at the first Activate() event and not again? I use a flag to
tell me if UI creation was done and if so I don't call that procedure.

When do you see the multiple instances of the UI? Is it on the first
appearance of the Inspector, after it's been activated/deactivated a few
times, or what?
 
O

orkdev

Thanks again Ken,

Menu creation was done on NewInspector event of Inspectors
Collection.

I had tried Activate event initially but ran into problems of multiple
instances again if focus moved away from that Window
(Created flag NOT used) .Using flag or testing whether menu already
created should solve this.

I could not understand why multiple instances were created on target
system but not on development machine - Option to use Word as email
editor may well be the difference here (and if so should be able to
reproduce this on development machine)

Multiple instances appeared on first appearance of inspector for New
Email (but not when viewing exiting received email)

I now think the problem arises out of a mistaken belief that
inspector_close event occurs when an inspector window is closed -
testing shows this not to be the case.

That's definitely given me something to work on

Peter

There should be no difference at all whether or not Exchange is being used
when you add UI to an open mail Inspector. Are you sure the difference isn't
WordMail or not being used?

You say multiple instances of your UI are there. Are you only creating iton
an Inspector at the first Activate() event and not again? I use a flag to
tell me if UI creation was done and if so I don't call that procedure.

When do you see the multiple instances of the UI? Is it on the first
appearance of the Inspector, after it's been activated/deactivated a few
times, or what?

--
Ken Slovak
[MVP - Outlook]http://www.slovaktech.com
Author: Professional Programming Outlook 2007.
Reminder Manager, Extended Reminders, Attachment Options.http://www.slovaktech.com/products.htm


The following VB6 code adds a Toplevel Menu with a single menu item
to the menu of a MailItem in Outlook. The function of the Addin is to
copy the email body to a database, hence only wanting to add menu to
MailItem menu. It also creates a toolbar with a single button.
"Vision Tools"
-- "Enter email into Vision Patient Record"
The menu is created each  time a new MailItem inspector is created (ie
Mail Item opened)
It is destroyed when the MailItem is closed
No problems with standalone Outlook 2003
The menu appears and functions correctly whenever a Mail Item is
opened including a new mail item
The problem occurs when Outlook 2003 is configured to work with *MS
Exchange*
Opening a received email - no problems
However when a New Mail is opened, the new menu appears multiple times
in the Mail Window eventually resulting in a ~~ error message. The
function of the Addin subsequently fails.
Checking for prior existence of menu before attempting to create the
menu makes no difference.
Any thoughts on where I am going astray or pointers to an alternative
approach gratefully received


####################################################
Public oMenuBar As Office.CommandBar
Public oMyControl As Office.CommandBarControl
Public WithEvents oMyCB As Office.CommandBarButton
Public oVisionToolBar As Office.CommandBar
Public WithEvents oMyCB2 As Office.CommandBarButton
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
   Dim objItem As Object
   'On Error Resume Next
   Set m_olMailItem = Nothing
   Set objInsp = Inspector
   Set objItem = objInsp.CurrentItem
   Select Case objItem.Class
           Case olMail
               Set m_olMailItem = objItem
               customiseOLMenu Inspector
           Case Else
               '
   End Select
End Sub
Private Sub objInsp_Close()
   'On Error Resume Next
   oVisionToolBar.Delete
   oMyControl.Delete
   m_olApp.ActiveInspector.CommandBars.ActiveMenuBar.Reset
   If m_olApp.ActiveExplorer Is Nothing And _
     m_olApp.Inspectors.Count <= 1 Then
       UnInitHandler
   End If
End Sub
Private Sub customiseOLMenu(olIsp As Outlook.Inspector)
' Customize the Outlook Menu structure and toolbar.
   Set oMenuBar = olIsp.CommandBars.ActiveMenuBar
   Set oMyControl = oMenuBar.Controls.Add(msoControlPopup, , , 7,
True)
   oMyControl.Caption = "Vision Tools"
   Set oMyCB = oMyControl.Controls.Add( _
       Type:=msoControlButton, Temporary:=True, Before:=1)
   With oMyCB
       .Caption = "Enter email into Vision Patient Record"
       .Enabled = IsVisionRunning
   End With
   Set oVisionToolBar = olIsp.CommandBars.Add("Vision Tools", 1, ,
True)
   With oVisionToolBar
       .Visible = True
       Set oMyCB2 = .Controls.Add(msoControlButton, , , , True)
   End With
   With oMyCB
       .Caption = "Enter email into Vision Patient Record"
       .DescriptionText = "Enter email into Vision Patient Record"
       .Style = msoButtonIconAndCaption
       .Picture = LoadResPicture(103, vbResBitmap)
   End With
   With oMyCB2
       .Caption = "Enter email into Vision Patient Record"
       .DescriptionText = "Enter email into Vision Patient Record"
       .Style = msoButtonIcon
       .Picture = LoadResPicture(103, vbResBitmap)
   End With
   With oVisionToolBar
       .Protection = msoBarNoCustomize
   End With
 
O

orkdev


2 minor residual issues

1. Can't show an hourglass cursor while form is loading
Screen.MousePointer= VbHorglass has no effect with Addins
SetCursor API doesn't work due to VB6 resetting cursor

2. assigning a picture to menu (ControlBarButton) fails if Inspector
is WordEditor
"Method '~' of object '~' failed"
but all answered here (although no solution)
http://support.microsoft.com/kb/286460
 
K

Ken Slovak - [MVP - Outlook]

1. Try calling DoEvents() after setting the cursor to prime the message
pump. It might not work, it sometimes does, sometimes doesn't. See if it
works in that context.

2. As that KB mentions you can't pass an IPictureDisp across process
boundaries. The workaround is to use the clipboard to store your image and
then to call the button's PasteFace() method. This needs to be done only for
WordMail.

What many of us do for that situation is to use a BMP that has the intended
masking areas set in the image in a color used in none of the image pixels.
For example, if magenta is not used in the image we set up the image to have
magenta where masking is desired. That also includes (always) the pixel at
0,0 so we know where to pick up the mask color.

See the thread at
http://www.devnewsgroups.net/group/microsoft.public.office.developer.outlook.vba/topic42279.aspx
for a link to a relevant KB article and some additional information about
this.
 
O

orkdev

1. Try calling DoEvents() after setting the cursor to prime the message
pump. It might not work, it sometimes does, sometimes doesn't. See if it
works in that context.

Thanks for that but still no joy so far. Will continue playing ...
2. As that KB mentions you can't pass an IPictureDisp across process
boundaries. The workaround is to use the clipboard to store your image and
then to call the button's PasteFace() method. This needs to be done only for
WordMail.

I've always been reluctant to use the clipboard in such a way (without
user's consent), particularly for a trivial task such as showing a
menu picture. From a user's practical point of view, potentially
losing data that you've just Cut to the clipboard ...
This addin will have to live without an illustrated menu
 
K

Ken Slovak - [MVP - Outlook]

The usual thing is to save the clipboard, clear it, do the button image and
then restore the original contents of the clipboard.
 

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