Custome Inspector Menus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have created a custom inspector menu that should only be available for contact inspectors. I've also created a custom toolbar (commandbar) with the same options which is working just fine i.e. shows up in only the contact inspector, but not in any other item type inspector and all of the buttons work fine no matter how many contact inspectors are open. Unfortunatley, I can not duplicate the functionality with the inpector menus. How can I get a custom inpector menu to enable only for contact inspectors and then stay enable after other inspectors are opened up?
 
I am confused: on one hand you are saying that you had no problems with the
contact inspectors, on the other hand you are saying that you cannot do the
same for the inspector menus? Do you mean inspectors vs explorers? If you do
mean inspectors, do you check the type of the item when Inspectors.Add
fires? Check Inspector.CurrentItem.Class or
Inspector.CurrentItem.MessageClass before modifying the toolbars/menus.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
I have created a custom inspector menu that should only be available for
contact inspectors. I've also created a custom toolbar (commandbar) with
the same options which is working just fine i.e. shows up in only the
contact inspector, but not in any other item type inspector and all of the
buttons work fine no matter how many contact inspectors are open.
Unfortunatley, I can not duplicate the functionality with the inpector
menus. How can I get a custom inpector menu to enable only for contact
inspectors and then stay enable after other inspectors are opened up?
 
Dmitry,

Thank you for your response. To clarify: the Inspector toolbar buttons I added work fine, but that the Inspector Menu buttons I added do not work fine. The toolbar buttons are on a regular custom command bar where as the Menu bar buttons are on a custom CommandBarPopUp control added to the CommandBar("Menu Bar") for the inspector. And, yes, I've tried using the process suggested in Randy Byrne's COM AddIn example in the knowledgebase that involves checking the currentitem class. Again, it works fine for the regular Inspector command bar, but not for the inspector menu bar.
--
Thanks and best regards,

Reb Dewinter


Dmitry Streblechenko (MVP) said:
I am confused: on one hand you are saying that you had no problems with the
contact inspectors, on the other hand you are saying that you cannot do the
same for the inspector menus? Do you mean inspectors vs explorers? If you do
mean inspectors, do you check the type of the item when Inspectors.Add
fires? Check Inspector.CurrentItem.Class or
Inspector.CurrentItem.MessageClass before modifying the toolbars/menus.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
I have created a custom inspector menu that should only be available for
contact inspectors. I've also created a custom toolbar (commandbar) with
the same options which is working just fine i.e. shows up in only the
contact inspector, but not in any other item type inspector and all of the
buttons work fine no matter how many contact inspectors are open.
Unfortunatley, I can not duplicate the functionality with the inpector
menus. How can I get a custom inpector menu to enable only for contact
inspectors and then stay enable after other inspectors are opened up?
 
What is your code that adds the buttons/menus?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
Dmitry,

Thank you for your response. To clarify: the Inspector toolbar buttons I
added work fine, but that the Inspector Menu buttons I added do not work
fine. The toolbar buttons are on a regular custom command bar where as the
Menu bar buttons are on a custom CommandBarPopUp control added to the
CommandBar("Menu Bar") for the inspector. And, yes, I've tried using the
process suggested in Randy Byrne's COM AddIn example in the knowledgebase
that involves checking the currentitem class. Again, it works fine for the
regular Inspector command bar, but not for the inspector menu bar.
--
Thanks and best regards,

Reb Dewinter


Dmitry Streblechenko (MVP) said:
I am confused: on one hand you are saying that you had no problems with the
contact inspectors, on the other hand you are saying that you cannot do the
same for the inspector menus? Do you mean inspectors vs explorers? If you do
mean inspectors, do you check the type of the item when Inspectors.Add
fires? Check Inspector.CurrentItem.Class or
Inspector.CurrentItem.MessageClass before modifying the toolbars/menus.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
I have created a custom inspector menu that should only be available
for
contact inspectors. I've also created a custom toolbar (commandbar) with
the same options which is working just fine i.e. shows up in only the
contact inspector, but not in any other item type inspector and all of the
buttons work fine no matter how many contact inspectors are open.
Unfortunatley, I can not duplicate the functionality with the inpector
menus. How can I get a custom inpector menu to enable only for contact
inspectors and then stay enable after other inspectors are opened up?
 
Dmitry,

Here is a sample of the relevant subroutines from my COM Add-in. I tried to get rid of all the code in them that wasn't relevant to Inspector Menu items. This is just one of many scenarios that I tried. I also tried not instantiating the Inspector menu in the Init-Handler routine and just doing it each time in the ContactButtonsOnOff routine. Below the routines I've listed the error message that I get in Outlook when I open an inspector form. Any help you can give me would be greatly appreciated.

Friend Sub InitHandler(ByVal oApp As Outlook.Application, ByVal strProgID As String)
Dim oiCommandBars As CommandBars
Dim oiTestBar As CommandBar
Dim oiTestMenu As CommandBarControl

Try
m_olOutlook = oApp 'Application object
m_ProgID = strProgID
m_olNamespace = m_olOutlook.Session

'add inspector menu bar
Dim myitem As Outlook.ContactItem
Dim oiMenuBar As CommandBar
myitem = CType(m_olNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Items.Add _
("IPM.Contact"), Outlook.ContactItem)
oiCommandBars = myitem.GetInspector.CommandBars
oiMenuBar = oiCommandBars.Item("Menu Bar")
oiTestMenu = CType(oiMenuBar.FindControl(Tag:="Test Menu"), CommandBarPopup)
If oiTestMenu Is Nothing Then oiTestMenu = CType(oiMenuBar.Controls.Add(Type:=MsoControlType.msoControlPopup, _
Before:=oiMenuBar.Controls("Help").Index, Temporary:=False), CommandBarPopup)
With oiTestMenu
.Enabled = True
.Caption = "Test"
.Tag = "Test Menu"
End With
Catch ex As SystemException
MsgBox("Error in Inithandler sub " & Err.Description)
End Try
End Sub
Private Sub CBBContactButtonsOnOff(ByVal oItem As Object, ByVal blnShow As Boolean)
Dim oAI As Outlook.AppointmentItem
Dim oJI As Outlook.JournalItem
Dim oCI As Outlook.ContactItem
Dim oDI As Outlook.DistListItem
Dim oTI As Outlook.TaskItem
Dim oPI As Outlook.PostItem
Dim oMI As Outlook.MailItemClass
'Use the OutlookItem class to retrieve Item Properties
Dim MyItem As New OutlookItem(oItem)
Dim oCommandBars As CommandBars
Dim oMenu As CommandBar
Dim oTestMenu As CommandBarControl

Try
oCommandBars = m_olInspector.CommandBars

'MsgBox("outlook.olobjectclass = " & CStr(MyItem.ObjectClass))
Select Case MyItem.ObjectClass
Case Outlook.OlObjectClass.olAppointment
oAI = CType(oItem, Outlook.AppointmentItem)
oTestMenu = CType(oAI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), _
CommandBarPopup)
Case Outlook.OlObjectClass.olMail
Case Outlook.OlObjectClass.olContact
oCI = CType(oItem, Outlook.ContactItem)
oTestMenu = CType(oCI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), CommandBarPopup)
Case Outlook.OlObjectClass.olDistributionList
oDI = CType(oItem, Outlook.DistListItem)
oTestMenu = CType(oDI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), CommandBarPopup)
Case Outlook.OlObjectClass.olPost
oPI = CType(oItem, Outlook.PostItem)
'oTestMenu = CType(oPI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), CommandBarPopup)
Case Outlook.OlObjectClass.olTask
oTI = CType(oItem, Outlook.TaskItem)
'oTestMenu = CType(oTI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), CommandBarPopup)
Case Outlook.OlObjectClass.olJournal
oJI = CType(oItem, Outlook.JournalItem)
'oTestMenu = CType(oJI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:=“Test Menuâ€), CommandBarPopup)
End Select
If Not oTestMenu Is Nothing Then
With oTestMenu
.Visible = blnShow
If MNUTestButton Is Nothing Then MNUTestButton = CType(oTestMenu.Controls.Add(Type:=MsoControlType.msoControlButton, _
Parameter:="TestButton"), CommandBarButton)
With MNUTestButton
.DescriptionText = "Test Button"
.BeginGroup = True
.Caption = "Test Button"
.FaceId = 1106
.Tag = "TestButton"
.TooltipText = "Test Button for contact"
.Style = MsoButtonStyle.msoButtonCaption
.OnAction = "!<" & m_ProgID & ">"
.Visible = blnShow
End With
End With
End If

oTestMenu = Nothing
oAI = Nothing
oJI = Nothing
oCI = Nothing
oDI = Nothing
oTI = Nothing
oPI = Nothing
oMI = Nothing
MyItem = Nothing

Catch ex As SystemException
MsgBox("error in CBBContactButtonsOnOff " & Err.Description)
End Try
End Sub
Private Sub m_olAppointmentItem_Open(ByRef Cancel As Boolean) Handles m_olAppointmentItem.Open
Try
CBBContactButtonsOnOff(m_olAppointmentItem, False)
Catch ex As Exception
MsgBox("error in m_olappointmentitem_open sub. " & Err.Description)
End Try

End Sub
Private Sub m_olContactItem_Open(ByRef Cancel As Boolean) Handles m_olContactItem.Open
Try
CBBContactButtonsOnOff(m_olContactItem, True)
Catch ex As Exception
MsgBox("error in m_olcontactitem_open sub. " & Err.Description)
End Try
End Sub

Error Message in Outlook:
"Error in CBBContactButtonsOnOFF Unspecified error"
 
When Open event is called, the inspector is not yet fully initialized.
Instead of using the Open event, use Inspectors.NewInspector event.
Have you looked at the ItemsCB sample COM addin at http://www.microeye.com ?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
Dmitry,

Here is a sample of the relevant subroutines from my COM Add-in. I tried
to get rid of all the code in them that wasn't relevant to Inspector Menu
items. This is just one of many scenarios that I tried. I also tried not
instantiating the Inspector menu in the Init-Handler routine and just doing
it each time in the ContactButtonsOnOff routine. Below the routines I've
listed the error message that I get in Outlook when I open an inspector
form. Any help you can give me would be greatly appreciated.
Friend Sub InitHandler(ByVal oApp As Outlook.Application, ByVal strProgID As String)
Dim oiCommandBars As CommandBars
Dim oiTestBar As CommandBar
Dim oiTestMenu As CommandBarControl

Try
m_olOutlook = oApp 'Application object
m_ProgID = strProgID
m_olNamespace = m_olOutlook.Session

'add inspector menu bar
Dim myitem As Outlook.ContactItem
Dim oiMenuBar As CommandBar
myitem =
CType(m_olNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContac
ts).Items.Add _
("IPM.Contact"), Outlook.ContactItem)
oiCommandBars = myitem.GetInspector.CommandBars
oiMenuBar = oiCommandBars.Item("Menu Bar")
oiTestMenu = CType(oiMenuBar.FindControl(Tag:="Test Menu"), CommandBarPopup)
If oiTestMenu Is Nothing Then oiTestMenu =
CType(oiMenuBar.Controls.Add(Type:=MsoControlType.msoControlPopup, _
Before:=oiMenuBar.Controls("Help").Index,
Temporary:=False), CommandBarPopup)
With oiTestMenu
.Enabled = True
.Caption = "Test"
.Tag = "Test Menu"
End With
Catch ex As SystemException
MsgBox("Error in Inithandler sub " & Err.Description)
End Try
End Sub
Private Sub CBBContactButtonsOnOff(ByVal oItem As Object, ByVal blnShow As Boolean)
Dim oAI As Outlook.AppointmentItem
Dim oJI As Outlook.JournalItem
Dim oCI As Outlook.ContactItem
Dim oDI As Outlook.DistListItem
Dim oTI As Outlook.TaskItem
Dim oPI As Outlook.PostItem
Dim oMI As Outlook.MailItemClass
'Use the OutlookItem class to retrieve Item Properties
Dim MyItem As New OutlookItem(oItem)
Dim oCommandBars As CommandBars
Dim oMenu As CommandBar
Dim oTestMenu As CommandBarControl

Try
oCommandBars = m_olInspector.CommandBars

'MsgBox("outlook.olobjectclass = " & CStr(MyItem.ObjectClass))
Select Case MyItem.ObjectClass
Case Outlook.OlObjectClass.olAppointment
oAI = CType(oItem, Outlook.AppointmentItem)
oTestMenu = CType(oAI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), _
CommandBarPopup)
Case Outlook.OlObjectClass.olMail
Case Outlook.OlObjectClass.olContact
oCI = CType(oItem, Outlook.ContactItem)
oTestMenu = CType(oCI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), CommandBarPopup)
Case Outlook.OlObjectClass.olDistributionList
oDI = CType(oItem, Outlook.DistListItem)
oTestMenu = CType(oDI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), CommandBarPopup)
Case Outlook.OlObjectClass.olPost
oPI = CType(oItem, Outlook.PostItem)
'oTestMenu = CType(oPI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), CommandBarPopup)
Case Outlook.OlObjectClass.olTask
oTI = CType(oItem, Outlook.TaskItem)
'oTestMenu = CType(oTI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), CommandBarPopup)
Case Outlook.OlObjectClass.olJournal
oJI = CType(oItem, Outlook.JournalItem)
'oTestMenu = CType(oJI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="Test Menu"), CommandBarPopup)
End Select
If Not oTestMenu Is Nothing Then
With oTestMenu
.Visible = blnShow
If MNUTestButton Is Nothing Then MNUTestButton =
CType(oTestMenu.Controls.Add(Type:=MsoControlType.msoControlButton, _
 
Yes, try to add the buttons in the NewInspector event handler.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
Hi, Dmitry, and thank you for your response.

I used a Micro Eye example as a pattern for the COM Add-In and he used the
Open event to access the command bar buttons and the NewInspector event to
assign values to the m_olcontactitem,m_olappointmentitem, etc. variables.
See code below. In one of the scenarios I used I know that I did try to do
something from that sub, but I can't remember how I had the code
configured - I just know it didn't work. Are you suggesting that I call the
ContactButtonsOnOff from the OldInspector.NewInspector sub?
Thanks for your help!

Private Sub m_olInspectors_NewInspector(ByVal Inspector As
Outlook.Inspector) Handles m_olInspectors.NewInspector
 
Dmitry,

I tried calling the ContactButtonsOnOff subroutine from the OldInspectors_NewInspectors sub as you suggested and am getting the following error: "The operation failed." at the line:

oTestMenu = ctype(oAI.GetInspector.CommandBars("Menu Bar").FindControl(Tag:="TestMenu"), CommandBarPopUp)

The menu name shows up on the Contact Menu Bar, but none of the buttons are available and when I close down Outlook and restart, the menu shows up a second time.

Any more suggestions?
 
Hmmm... Try to pass the Type parameter too. Do you create the controls as
temporary?

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool


Reb DeWinter said:
Dmitry,

I tried calling the ContactButtonsOnOff subroutine from the
OldInspectors_NewInspectors sub as you suggested and am getting the
following error: "The operation failed." at the line:
oTestMenu = ctype(oAI.GetInspector.CommandBars("Menu
Bar").FindControl(Tag:="TestMenu"), CommandBarPopUp)
The menu name shows up on the Contact Menu Bar, but none of the buttons
are available and when I close down Outlook and restart, the menu shows up a
second time.
 
I have tried creating cotrols as temporary and what happens is that when I open up another inspector while the Contact inspector is still open, I no longer have functionality when I return to the Contact inpector.
 
I did try making the menu controls temporary, but then when I open up another inspector and then return back to the Contact inspector, the controls no longer function properly.
 
Yes, because you need to wrap and treat each *instance* of an inspector
separately.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool

Reb DeWinter said:
I did try making the menu controls temporary, but then when I open up
another inspector and then return back to the Contact inspector, the
controls no longer function properly.
 
I can't help with VB.NET, I don't have that high a threshold of pain :)

It does look like I left out some module level declarations that should be
there, I'll go over that code and post a revised wrapper example over the
weekend.

Randy didn't include an Inspector wrapper in his example, ItemsCB, because a
working Inspector wrapper hadn't yet been developed when he wrote that
sample. That wasn't developed until we did some work on a commercial project
together. ItemsCB will be updated at some point to include an Inspector
wrapper as well as lots of other things. We don't have a target date for
that however, it depends on when we can find the time to work on it.




Reb DeWinter said:
Hi, Dmitry!

I've tried porting the Slovak code you directed me to into my COM Add-In,
but it is not going well. First of all, the Slovak code is VB 6.0 and I'm
using VB.Net so I'm having to make several adjustments and things are coming
up missing - like variables that were never declared so I'm not sure if they
are VB 6.0 default variables or just variables that need to be declared.
Second, I'm wondering why Randy Byrne would not have included similar
functionality in his COM Add-In sample if it was necessary. Maybe just
because the sample code does not use inspector menus? Or is it obsolete in
VB.Net? So before I spend several more hours trying to integrate this new
code into my COM Add-in I wanted to confirm with you that I'm adding the
right stuff in the right places. and maybe get some insite into some of the
syntax errors:
I integrated the code from Slovak's
Private Sub colInsp_NewInspector(ByVal Inspector As Inspector)
sub into the OlInspector_NewInspector sub in my OutAddIn class (similar to
the one used in Byrne's example).
Then I created a new class called clsInspWrap.vb and a new module called
basOutInsp.vb to house the code he references for the inspector wrapper just
as he suggests. In the clsInspWrap.vb class, the following variables are
showing as never being declared:
m_strMailID, m_strContactID, strKey, m_oControlBar. I can't find them
declared as pulblic variables anywhere else in his code so should I add
public declarations for them at the class or module level?
I also had to change the property statements to update them to VB.Net - does this look correct?

Public Property MailItem(ByVal objMail As Outlook.MailItem)

Set(ByVal Value)
m_objMail = objMail
m_blnMailInspector = True
m_strMailID = objMail.EntryID
End Set
Get
Return m_objMail
Return m_blnMailInspector
Return m_strmailid
End Get

End Property

Public Property ContactItem(ByVal objContact As Outlook.ContactItem)

Set(ByVal Value)
m_objContact = objContact
'm_strContactID = objContact.Importance
m_blnMailInspector = False
End Set
Get
Return m_objContact
'Return m_strcontactid
Return m_blnMailInspector
End Get
End Property

Public Property Inspector(ByVal objInspector As Outlook.Inspector)

Set(ByVal Value)
m_objInsp = objInspector
'
End Set
Get
'Return m_objInsp
Inspector = m_objInsp
Return Inspector
End Get

End Property

Public Property Key(ByVal lngID As Long)
Set(ByVal Value)
m_intID = lngID
End Set
Get
Key = m_intID
'Return m_intID
Return Key
End Get
End Property

In the basOutInsp.vb module, it doesn't like some of the syntax and I'm
not quite sure what to do with it. For example, Slovak's code has this
statement:
 
Back
Top