Outlook 2007 Control.Context problem VB6.0

  • Thread starter Thread starter n777krish
  • Start date Start date
N

n777krish

Hello All,

I have added a combobox to the Outlook 2007 RibbonX.

Now as per the Outlook Com-addin samples (VB.Net samples), I am writing
a function to Find the Outlook Inspector that is currently selected
with-in the com addins inspectors collection. The function in VB 6.0
code is as follows:
************************************************************************************************
Private Function FindOutlookInspector(ByVal window As Object) As
clsInspWrap
Dim colInsp As clsInspWrap

Set FindOutlookInspector = Nothing
For Each colInsp In g_colInspWrap
If colInsp.Inspector Is window Then
Set FindOutlookInspector = colInsp
End If
Next colInsp
End Function
************************************************************************************************

The g_colInspWrap is the collection of inspectors that the addin
maintains.

The "colInsp.Inspector" returns an Outlook.Inspector object.

This line "If colInsp.Inspector Is window Then" never yields to True.
the "window" being passed into the function is the control.context that
gets passed into the callbacks.

Now, according to some tests that I carried out I observe the
following:
1. In the callback for a control if I compare "ActiveInspector Is
control.context" or vice-versa then this also yields false. Why
wouldn't this return true since both control.context and
ActiveInspector are referring to the same object?

2. In FindOutlookInspector function if I compare "colInsp.Inspector Is
golApp.ActiveInspector" (golApp is the global Outlook Application
object) instead of "window", then I observe that the ActiveInspector
still refers to the previous inspector when multiple are open and not
the one that I just clicked. I thought I could use the ActiveInspector
to find the appropriate inspector but this does not work because of
this problem.

What am i doing wrong? Why doesn't the code return true even when both
are refering to the same object?

Does control.context refer to some thing else? Has anyone been able to
write this successfully in VB6.0?

I am testing this code in Outlook 2007 Beta2. All the VB.Net sample's
indicate that this is how it is to be done but in VB6.0 i am finding it
different.

I would really appreciate the help and guidance.

Regards,
Neil Goundar.
 
Are you using Beta 2 or Beta 2 TR? The comparison for control.context Is
Inspector doesn't work until B2TR. It also works in the RTM version.

You also have to be careful of when you check for ActiveInspector and make
sure it's populated.

In my VB6 code for the RTM version I can use (Inspector Is control.context)
and it works.
 
Dear Ken,

Thank you for your guidance. Without your guidance I would still be
messing around in the code. Yes that was an issue with Beta 2. I
downloaded the B2TR and the comparison works fine now.

I have another question based on some further tests that I have made.
This is what i have observed in the VB 6.0 code that I am working on:

1. I open a New Inspector and select an Item from the combobox that I
have added to the RibbonX. The selection made on this inspector is
stored in a variable inside the Inspector Wrap as per the VB.NET
samples. Now, I close this new inspector (code removes it from the
global inspectors collection successfully). I open a new Inspector and
I observe that in the selection is to what i selected in the other
inspector. I try to debug and find that the callbacks dont fire after I
have just closed one inspector and opened a new one.

When I open multiple inspectors and make different choises in the
combobox these are tracked successfully on the inspectors and they
maintain what was selected since the callbacks are called here.

Why would this happen? A New Inspector is loaded into the collection
also.

Thank you in advance for your help.

Regards,
Neil Goundar.
 
It's hard to say without knowing exactly how your code is structured.

What I've been doing is assigning my Inspector wrapper class in
NewInspector. The first time any Inspector type is opened the GetCustomUI
callback is fired. That and all my other ribbon callbacks are kept in a
class module that has scope over the life of the addin. I happen to use the
VB6 designer class for that in the VB6 test addins I've done.

At the time GetCustomUI fires the Ribbon_OnLoad callback hasn't fired yet.
It also hasn't fired when NewInspector fires (the first time). So I set up a
dummy Office.IRibbonUI object in the wrapper class and fill in the ribbon
reference when Ribbon_OnLoad fires. I iterate the Inspector wrapper
collection and set the class ribbon object in Ribbon_OnLoad for every
existing wrapper class.

When Inspector.Activate fires in the wrapper class (for the first time) I
call to invalidate the ribbon using m_Ribbon.Invalidate(). I could also just
invalidate specific controls, such as your combobox.

The Invalidate method forces ribbon callbacks that I then use to initialize
my controls, such as setting toggleButton states and combobox selections.
Without invalidating the ribbon control it would just keep whatever state it
had.

If callbacks are failing to fire then it's a question of scope most likely.
Something is going out of scope. What is going out of scope is up to you to
determine :)
 
Hello Ken,

My code was a bit different and I have changed it as to how your code
is organized. The problem still exists though.

I carried out tests and am observing the following:
1. I open a new inspector. The ribbon onload event does get fired and I
initialize the dummy m_ribbon in the inspector wrapper class. Now I
close this inspector and if I open another inspector the Ribbon_OnLoad
and all the other callbacks do not get called.

Public Sub Ribbon_OnLoad(ByVal ribbon As Office.IRibbonUI) is declared
in the designer class as is yours.

Why wouldn't the Ribbon_OnLoad get called? The RibbonOn_Load and other
callbacks are in the Designer class. Does the Ribbon_OnLoad get called
for every inspector that gets created? I was not able to find
information on this in the documents.

Also, I observed in the VB.NET samples that a ribbon object was being
stored in the Connect class and there was also another dummy one in the
inspector wrap class. I tried to change it as this but since
Ribbon_OnLoad is not being called the dummy m_ribbon in the new
inspector that is being created is not being set.

Any ideas on why this might happen?

I am using Beta 2 TR version of Office running on a Windows XP machine.


Thank you in advance for your help. I am carrying out other tests and
hope fully find out why this is happening soon.

Regards,
Neil Goundar.
 
Hello Ken,

I have been trying out some other things and have got it working. I
need your guidance as to what I am doing is correct or not.

I have declared a Public m_ribbon object in one of the modules in my
code.

In Public Sub Ribbon_OnLoad(ByVal ribbon As Office.IRibbonUI) function
in the designer class i am assigning the m_ribbon object to the ribbon
(Set m_ribbon = ribbon).

I have got rid of the m_ribbon in each inspector class and have only
this global ribbon object to work off. Now using this object in the
inpector Activate event, i invalidate the control (combobox) to cause
the events to fire again and it is able to update the display text as
it should.

Is this approach acceptable in terms of having the global ribbon
object. If i have the dummy m_ribbon object in the inspector class and
instantiate this in the Ribbon_onLoad for all open inspectors I am
finding that the OnLoad event does not get called as per my previous
post. Therefore, I am using a global ribbon object to assign it.

Now, I have one more question:
When I get the first ribbon object will this object refer to all
inspectors that I open? This is what I think is happening since I am
able to invalidate controls on other inspectors using the single
object.

I would really appreciate your help on this. Also, I made a reply
before this that you may not have read. Could you read that to see what
I am observing.

Thank you,
Neil Goundar.
 
Ribbon_OnLoad fires only once, the first time any type of ribbon is
initialized (in other words only when the first Inspector is opened). The
class level RibbonUI object is instantiated once only.

In the wrapper class the RibbonUI object can be set in NewInspector except
for that first Inspector. That's why I iterate any wrappers and instantiate
the RibbonUI object in Ribbon_OnLoad then, it's to make up for the timing
issue of when that event fires versus when NewInspector fires.

After that first Inspector the class level RibbonUI object is valid so the
wrapper ribbon object is just instantiated from NewInspector.

The reason to use that wrapper class ribbon object is so you have a valid
object to work with to call the Invalidate() and InvalidateControl()
methods.
 
Yes, your approach is valid. And yes Ribbon_OnLoad will only fire once an
Outlook session, after the first Inspector is opened, after NewInspector and
before Inspector.Activate.

A global can be used. It's just programming preference that I have an object
in each Inspector wrapper class, as well as the desire to have as much
common code as possible among VB6, VB.NET and C# addins that I write.
 
Dear Ken,

I would like to thank you for all the help you have provided me with so
far with the issues that i have faced.

Regards,
Neil Goundar.

Thank you.
 
Back
Top