Outlook Banter

Outlook Banter (http://www.outlookbanter.com/)
-   Add-ins for Outlook (http://www.outlookbanter.com/add-ins-outlook/)
-   -   Inspector Wrapper (http://www.outlookbanter.com/add-ins-outlook/65607-inspector-wrapper.html)

Goran January 23rd 08 01:59 AM

Inspector Wrapper
 
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


Ken Slovak - [MVP - Outlook] January 23rd 08 02:41 PM

Inspector Wrapper
 
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 Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"goran" wrote in message
...
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



Goran January 23rd 08 06:20 PM

Inspector Wrapper
 
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

"Ken Slovak - [MVP - Outlook]" wrote:

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 Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"goran" wrote in message
...
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




Ken Slovak - [MVP - Outlook] January 23rd 08 06:36 PM

Inspector Wrapper
 
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 Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"goran" wrote in message
...
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



Goran January 28th 08 06:36 PM

Inspector Wrapper
 
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

"Ken Slovak - [MVP - Outlook]" wrote:

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 Slovak
[MVP - Outlook]
http://www.slovaktech.com
Author: Professional Programming Outlook 2007
Reminder Manager, Extended Reminders, Attachment Options
http://www.slovaktech.com/products.htm


"goran" wrote in message
...
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




Ken Slovak - [MVP - Outlook] January 28th 08 07:12 PM

Inspector Wrapper
 
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.

--
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


"goran" wrote in message
...
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



Goran January 30th 08 02:25 PM

Inspector Wrapper
 
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

"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
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


"goran" wrote in message
...
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




Ken Slovak - [MVP - Outlook] January 30th 08 02:58 PM

Inspector Wrapper
 
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.

--
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


"goran" wrote in message
...
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



Goran January 30th 08 06:05 PM

Inspector Wrapper
 
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


"Ken Slovak - [MVP - Outlook]" wrote:

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.

--
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


"goran" wrote in message
...
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




Ken Slovak - [MVP - Outlook] January 30th 08 08:07 PM

Inspector Wrapper
 
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.

--
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


"goran" wrote in message
...
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




All times are GMT +1. The time now is 12:25 PM.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2006 OutlookBanter.com