Inspector Wrapper

  • Thread starter Thread starter goran
  • Start date Start date
G

goran

Hi,
I used MicroEye example and Ken's InspectorWrapper to create Outlook 2003
add-in. This add-in adds a new CommandBar with a dropdown and command button
to the outlook toolbar. Everything is fine if I open multiple emails from
Inbox. I see exactly one
commandbar with dropdown and a button in it. But when I open multiple new
mail inspectors, it adds 2 command bars for second inspector, 3 for third etc.
It looks like it carries command bars from previously opened inspectors. I
use colInsp_NewInspector method in OutAdddin class to call AddInsp method in
the bas module to add each inspector to the collection.
I use mail_open method to call CreateMenus where I assign unique tag to each
commandbar, dropdown and a button. When I delete one of those commandbars, it
disappears from all open inspectors. I should mention that Email editor is
Word editor. Any ideas?
Thanks in advance,

Goran
 
No need to post this 3 times.

WordMail is completely different than an Outlook editor Inspector. In
WordMail for Outlook 2003 and earlier the UI you add gets placed wherever
the CustomizationContext points (Word.Application.CustomizationContext).

That has a number of implications. First, if CustomizationContext.Saved is
False then when Outlook is closed the user will get prompted to save
Normal.dot (if that's where CustomizationContext points) if they have the
setting to be prompted to save Normal.dot. If they don't have that setting
then the UI will just be saved and reappear the next time Word is opened.

Second, any UI you add will appear always unless explicitly removed. Word
doesn't honor the Temporary = True setting you might apply when you create
the UI. So you must explicitly delete the UI you created when the
item/Inspector is closing.

Finally, since Word will show all UI instances not only when WordMail items
are open but also in Word documents (try opening a doc when Inspectors are
open to see that) you need code to see if a Word window is a WordMail window
and which WordMail window if more than one is open.

That final piece is the key. Use a Word event handler to handle
Window_Activate. In that event handler check that window for
wn.EnvelopeVisible = True. If True it's a WordMail window. If False it's a
doc window. In that case you iterate all the Word CommandBars and see which
are yours and which are not. Disable yours and set Visible = False for each
one. If it is WordMail use code to match your unique Tag (which should
include the wrapper class Key value) with the current Inspector. That UI
gets enabled and made visible, any other UI gets disabled and made
invisible.
 
Ken,

First, sorry about multiple posts, but I was getting an error when I tried
to post, so I thought my post didn't go through. I didn't see my post in the
thread all day yesterday that's why I did this 3 times.
Thanks much for your response. I new WordMail is special, and I explicitly
remove those buttons on mail_close event so I don't have problems with
WordMail saving this commandbar. My only problem is when I have multiple new
mail windows open at the same time. Where do I find Window_Activate event?

Thanks very much,

Goran
 
Inspector.WordEditor is actually a Word.Document object. WordEditor.Parent
is the Word.Application object. If an item is a WordMail item you use that
methodology to get a Word Application object. That allows you to handle Word
events. WindowActivate is a Word.Application event that passes you a window
reference for the window that's being activated.
 
Ken,

Thank you very, very much once again.
I did exactly what you said. Got hold of WordMail object, and use
Window_Activate event to check for the CommandBar. In every open window I
make CommandBar from previous window invisible, and I see exactly one
CommandBar in each window.However, If I right-click on the toolbar I see list
of all those Command bars which are not visible. I tried to call
CommadBar.delete instead visible=false but then they dissapear in every
window, even in one where that one should be visible. Any idea how to fix
this? Also, now I get Outlook security warning when I open new email 'A
program is trying to access email addresses..'. How can I avoid this?

Thanks a lot for your time and your help.

Goran
 
Both disable and make invisible those toolbars you want to not show.

I have no idea why you're running into the Outlook object model security
since I don't know what your code is doing or where in your code you're
triggering the security. In general that can be anywhere that you are
possibly harvesting email addresses. See
http://www.outlookcode.com/article.aspx?id=52 for more on the security and
your options.
 
Thanks a lot Ken,

The Outlook Security warning pops up on the line where I test if the editor
is word editor: if m_objinsp.WordEditor=true. Strange, it has nothing to do
with email addresses.

Goran
 
Access to WordEditor is restricted unless you're running in-process on
Outlook 2003 or 2007, or running on Outlook 2007 with up-to-date A-V from an
outside program. If you just want to know if an item is WordMail you can use
the Inspector.IsWordMail Boolean. On Outlook 2007 that will always be true.

I use Redemption so I can get at WordEditor without security restrictions.
Unless you use Redemption you will get the security unless you're running
under the conditions I mentioned above. About the only alternative I've
found is to use Win32 API calls to get at the window that represents the
WordMail window and then find WordEditor under that as a Word.Document
object.

For that I use FindWindow() and GetForegroundWindow() to get the hWnd of the
Inspector window. From there I enumerate the child windows looking for
"OpusApp" as the window caption. From there I look for a child window with a
class name of "_WwG" for Outlook 2003 and lower and for "_WwF" for Outlook
2007. From there I use AccessibleObjectFromWindow() with the resulting hWnd
to look for the required characteristics of UID1 and OBJID_NATIVEOM.

UID1 is defined as UUID with values of:

.Data1 = &H20400
.Data4(0) = &HC0
.Data4(7) = &H46

where UUID is:

Public Type UUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(0 To 7) As Byte
End Type

and OBJID_NATIVEOM is:

Const OBJID_NATIVEOM = &HFFFFFFF0

The result returned by AccessibleObjectFromWindow() is then checked for a
return value of 0 and if that's the case then the ppvObject As Object final
argument to AccessibleObjectFromWindow() is used to get the Word document
object, where if ob is ppvObject then ob.Document is the Word document
object represented by WordEditor.

Lots of Win32 API callbacks there but it's the only safe way to get
WordEditor without triggering the security under conditions where the
security would fire.

You'd have to write your own procedures for that and the Win32 callbacks,
I've never seen this technique documented anywhere, and it took me a lot of
research and testing to come up with the procedures to retrieve WordEditor
that way.
 
Thanks Ken.
I will use redemption to avoid this. I added the code to disable and make
invisible those toolbars from prevously opened inspectors but now they are
disableb not only onthe current inspectors but in all others that are opened
before. I can't match wrapper with current inspector no matter what I try.
Where should I try to match current inspector with unique tag of wrapper to
be able to see Commandbar1 only in Inspector1 CommandBar2 only in inspector2
etc?

Sorry about this.

Thanks once again,

Goran
 
Well, what I do is use a unique string, maybe something like
"myWordMailToolbar". Then I append the Key value of my Inspector wrapper. So
wrapper class with Key = 1 has a Tag value of "myWordMailToolbar1". In
WindowActivate I get the Key value and check for all command bars with the
string "myWordMailToolbar" in their Tag values if the toolbar is BuiltIn =
false. Any that match are my user created toolbars.

Then I match the full Tag value to see which bar belongs to the active
Inspector and enable and make visible that one. Any others with the partial
Tag but a different Key value at the end get disabled and made invisible.

Your mileage may vary.
 
Hi all,
This code works fine, but when the new Email window is shown - for a moment
the user sees how toolbars are flashing because my code updates CommandBar
collection (it shows/hide my custom toolbars). What can i do with
flashing??? Thanks.

Private Sub Word_WindowActivate(ByVal Doc As
Microsoft.Office.Interop.Word.Document, ByVal Wn As
Microsoft.Office.Interop.Word.Window)
Dim sEmailToolbarName As String = EMAIL_TOOLBAR_NAME
Dim sCurrentToolbar As String = [String].Empty
If Wn.EnvelopeVisible = True Then
Dim sCurrentIndex As String =
Globals.ThisApplication.ActiveInspector.CurrentItem.Companies
Dim sActiveToolBar As String = sEmailToolbarName +
sCurrentIndex
Try
For i As Integer = Doc.CommandBars.Count To 1 Step -1
If Doc.CommandBars.Item(i).BuiltIn = False Then
sCurrentToolbar = Doc.CommandBars.Item(i).Name
If sCurrentToolbar.Contains(sEmailToolbarName) =
True _
AndAlso sCurrentToolbar.Contains(sActiveToolBar)
= False Then
Doc.CommandBars.Item(i).Enabled = False
Doc.CommandBars.Item(i).Visible = False
Continue For
End If
If sCurrentToolbar.Contains(sActiveToolBar) =
True Then
Doc.CommandBars.Item(i).Enabled = True
Doc.CommandBars.Item(i).Visible = True
LoadSettings(Doc.CommandBars.Item(i))
End If
Else
Exit For
End If
Next
Catch ex As Exception
Common.Trace.Log(ex)
End Try
End Sub
 
You can try turning off screen updating in Word and see if that helps.
 
or you can minimize inspector window before you start removing CommandBars
and maximize it se activate after you are done.

Thanks,

Goran

Ken Slovak - said:
You can try turning off screen updating in Word and see if that helps.




mwebb said:
Hi all,
This code works fine, but when the new Email window is shown - for a
moment
the user sees how toolbars are flashing because my code updates CommandBar
collection (it shows/hide my custom toolbars). What can i do with
flashing??? Thanks.

Private Sub Word_WindowActivate(ByVal Doc As
Microsoft.Office.Interop.Word.Document, ByVal Wn As
Microsoft.Office.Interop.Word.Window)
Dim sEmailToolbarName As String = EMAIL_TOOLBAR_NAME
Dim sCurrentToolbar As String = [String].Empty
If Wn.EnvelopeVisible = True Then
Dim sCurrentIndex As String =
Globals.ThisApplication.ActiveInspector.CurrentItem.Companies
Dim sActiveToolBar As String = sEmailToolbarName +
sCurrentIndex
Try
For i As Integer = Doc.CommandBars.Count To 1 Step -1
If Doc.CommandBars.Item(i).BuiltIn = False Then
sCurrentToolbar = Doc.CommandBars.Item(i).Name
If sCurrentToolbar.Contains(sEmailToolbarName)
=
True _
AndAlso
sCurrentToolbar.Contains(sActiveToolBar)
= False Then
Doc.CommandBars.Item(i).Enabled = False
Doc.CommandBars.Item(i).Visible = False
Continue For
End If
If sCurrentToolbar.Contains(sActiveToolBar) =
True Then
Doc.CommandBars.Item(i).Enabled = True
Doc.CommandBars.Item(i).Visible = True
LoadSettings(Doc.CommandBars.Item(i))
End If
Else
Exit For
End If
Next
Catch ex As Exception
Common.Trace.Log(ex)
End Try
End Sub
 
That's possible too, but it would flash the window as it was minimized and
then restored.
 
Back
Top