|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
remove custom add-in toolbars for editable email windowsI have an Outlook Add-in that takes the currently selected email(s) and when the user clicks a button, it saves them in some predetermined directory on their computer. Everything works great unless the user is in an editable email window. An editable email window being (new, reply, reply all, forward). In these cases, I would like to remove our add-in from these windows. Everything seems to be working well for reply, reply all, forward, we hooked into the appropriate events for those actions both under the New_Inspector, as well as in the ActiveExplorer, but I haven't been able to figure out how to handle the new email window. If anyone has any suggestions I would be greatly appreciative! As an aside, the main reason that we want to remove the add-in from those editable windows is because we have been unable to find a way to get all of the contents of the edited/non-saved email into a file without altering or requiring the user to save the email. Thanks, Ryan If I understand what you are asking is how to not add your UI to an email
window? Just don't add it to any Inspectors opened in the NewInspector event handler. If you want it on other types of items just checked the CurrentItem.Class property of the Inspector passed to you in NewInspector and don't add the UI if it's Class = olMail. If want you want to do is remove the UI then just find what you added and delete it. -- Show quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Ryan Taylor" <Ryan Tay***@discussions.microsoft.com> wrote in message news:1C5A5099-4778-4749-A08D-28295ACDA7A5@microsoft.com... > Hello, > > I have an Outlook Add-in that takes the currently selected email(s) and > when > the user clicks a button, it saves them in some predetermined directory on > their computer. Everything works great unless the user is in an editable > email window. > > An editable email window being (new, reply, reply all, forward). In these > cases, I would like to remove our add-in from these windows. Everything > seems to be working well for reply, reply all, forward, we hooked into the > appropriate events for those actions both under the New_Inspector, as well > as > in the ActiveExplorer, but I haven't been able to figure out how to handle > the new email window. If anyone has any suggestions I would be greatly > appreciative! > > As an aside, the main reason that we want to remove the add-in from those > editable windows is because we have been unable to find a way to get all > of > the contents of the edited/non-saved email into a file without altering or > requiring the user to save the email. > > Thanks, > Ryan Hi Ken,
Thank you for your reply. You are partially correct in your understanding, I would like to not add/remove my UI to an email window, however it depends on the type of window. For example, if the user double clicks on an email in their inbox, I would like the add-in toolbar to be present. If instead the user clicks "New" or reply (these being editable windows) I do not want the toolbar to be present. I guess I am having trouble distinguishing between an editable, and a non editable window so the way I have determined it, is by hooking into those events that create editable windows (reply, reply all, forward) and removing my UI from there doing something like below: _mailEvents.Forward += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ForwardEventHandler(mailEvents_Forward); _mailEvents.Reply += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(mailEvents_Reply); and removing my menu in there. Unfortunately, I do not how to account for the "New" email situation. I could not find a _MailEvents.NewEmail event to hook into. Thanks, Ryan Show quote "Ken Slovak - [MVP - Outlook]" wrote: > If I understand what you are asking is how to not add your UI to an email > window? Just don't add it to any Inspectors opened in the NewInspector event > handler. If you want it on other types of items just checked the > CurrentItem.Class property of the Inspector passed to you in NewInspector > and don't add the UI if it's Class = olMail. > > If want you want to do is remove the UI then just find what you added and > delete it. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Ryan Taylor" <Ryan Tay***@discussions.microsoft.com> wrote in message > news:1C5A5099-4778-4749-A08D-28295ACDA7A5@microsoft.com... > > Hello, > > > > I have an Outlook Add-in that takes the currently selected email(s) and > > when > > the user clicks a button, it saves them in some predetermined directory on > > their computer. Everything works great unless the user is in an editable > > email window. > > > > An editable email window being (new, reply, reply all, forward). In these > > cases, I would like to remove our add-in from these windows. Everything > > seems to be working well for reply, reply all, forward, we hooked into the > > appropriate events for those actions both under the New_Inspector, as well > > as > > in the ActiveExplorer, but I haven't been able to figure out how to handle > > the new email window. If anyone has any suggestions I would be greatly > > appreciative! > > > > As an aside, the main reason that we want to remove the add-in from those > > editable windows is because we have been unable to find a way to get all > > of > > the contents of the edited/non-saved email into a file without altering or > > requiring the user to save the email. > > > > Thanks, > > Ryan > > There really isn't a good way to see if an email Inspector is read, new,
reply, forward or whatever. There are also ways to reply or forward that you won't pick up the way you're doing things. A reply (an example) can be made from an open item, from a selected item using the Explorer menu commands, from a right-click on a non-selected item and selecting Reply in the context menu. I usually use a combination of tests but that's still a hack. A new, unsaved email item has EntryID = "". A previously saved item will have an EntryID. If RE: or FW: is in the subject that indicates a reply or forward, although that's English specific (AW: in German for example). The rule is start with up to 3 characters followed by a colon. If PR_MESSAGE_FLAGS is MSGFLAG_UNSENT then it's an unsent message. If PR_IN_REPLY_TO_ID is there it's a reply, although that may not be there if Exchange isn't being used. -- Show quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Ryan Taylor" <Ryan Tay***@discussions.microsoft.com> wrote in message news:78496C3E-35F8-442F-812C-0D8CFAAC6064@microsoft.com... > Hi Ken, > > Thank you for your reply. You are partially correct in your > understanding, > I would like to not add/remove my UI to an email window, however it > depends > on the type of window. For example, if the user double clicks on an email > in > their inbox, I would like the add-in toolbar to be present. If instead > the > user clicks "New" or reply (these being editable windows) I do not want > the > toolbar to be present. > > I guess I am having trouble distinguishing between an editable, and a non > editable window so the way I have determined it, is by hooking into those > events that create editable windows (reply, reply all, forward) and > removing > my UI from there doing something like below: > > _mailEvents.Forward += new > Microsoft.Office.Interop.Outlook.ItemEvents_10_ForwardEventHandler(mailEvents_Forward); > _mailEvents.Reply += new > Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(mailEvents_Reply); > > and removing my menu in there. Unfortunately, I do not how to account for > the "New" email situation. I could not find a _MailEvents.NewEmail event > to > hook into. > > Thanks, > Ryan Hi Ken,
Thank you for your continued help! One of your suggestions appears to do exactly what I am looking for. I starting searching for ways to access PR_MESSAGE_FLAGS and I came across a program called OutlookSpy ( http://www.dimastr.com/outspy/) This made it really easy to compare different message attributes to find what was the same/different for new/reply/forward/open messages. Per your suggestions, I started exploring for MSGFLAG_UNSENT. I was unable to easily find how to access the MAPI Message object, but I did find a nice property that reflects what you were talking about: MailItem myMail; myMail.Sent property. This property appears to always be set to false when I am in an editable window, and true when I have only opened the email (but not to edit). So I can easily check this property and remove my add-in at will (Since everything eventually goes through my MSOutlook.InspectorsEvents_NewInspectorEventHandler, regardless of how the user opened/replied/etc the email. So my solution was to remove the that hooked into the ActiveExplorer events, as well as the MailItem specific code hooking into _mailItem.Forward/Reply/etc. I have instead replaced it with: private void Inspectors_NewInspector(Inspector inspector) { if (inspector.CurrentItem is MSOutlook.MailItem) { MailItem current = inspector.CurrentItem as MailItem; if(current.Sent) { RemoveAddin(...); } } } Thank you very much for your help! Ryan Show quote "Ken Slovak - [MVP - Outlook]" wrote: > There really isn't a good way to see if an email Inspector is read, new, > reply, forward or whatever. There are also ways to reply or forward that you > won't pick up the way you're doing things. A reply (an example) can be made > from an open item, from a selected item using the Explorer menu commands, > from a right-click on a non-selected item and selecting Reply in the context > menu. > > I usually use a combination of tests but that's still a hack. > > A new, unsaved email item has EntryID = "". A previously saved item will > have an EntryID. > > If RE: or FW: is in the subject that indicates a reply or forward, although > that's English specific (AW: in German for example). The rule is start with > up to 3 characters followed by a colon. > > If PR_MESSAGE_FLAGS is MSGFLAG_UNSENT then it's an unsent message. > > If PR_IN_REPLY_TO_ID is there it's a reply, although that may not be there > if Exchange isn't being used. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Ryan Taylor" <Ryan Tay***@discussions.microsoft.com> wrote in message > news:78496C3E-35F8-442F-812C-0D8CFAAC6064@microsoft.com... > > Hi Ken, > > > > Thank you for your reply. You are partially correct in your > > understanding, > > I would like to not add/remove my UI to an email window, however it > > depends > > on the type of window. For example, if the user double clicks on an email > > in > > their inbox, I would like the add-in toolbar to be present. If instead > > the > > user clicks "New" or reply (these being editable windows) I do not want > > the > > toolbar to be present. > > > > I guess I am having trouble distinguishing between an editable, and a non > > editable window so the way I have determined it, is by hooking into those > > events that create editable windows (reply, reply all, forward) and > > removing > > my UI from there doing something like below: > > > > _mailEvents.Forward += new > > Microsoft.Office.Interop.Outlook.ItemEvents_10_ForwardEventHandler(mailEvents_Forward); > > _mailEvents.Reply += new > > Microsoft.Office.Interop.Outlook.ItemEvents_10_ReplyEventHandler(mailEvents_Reply); > > > > and removing my menu in there. Unfortunately, I do not how to account for > > the "New" email situation. I could not find a _MailEvents.NewEmail event > > to > > hook into. > > > > Thanks, > > Ryan > > I wouldn't rely on testing for that in NewInspector, especially if your
users will be running Outlook 2007 at some point. It's a weak object reference that you get in NewInspector and it isn't recommended to access more than Class and MessageClasss in that event handler. I'd do it in the first Inspector.Activate() event and that's where I'd be calling to create the UI. Inspector.CommandBars or the Inspector Ribbon aren't guaranteed to be instantiated until Activate() fires. OutlookSpy is an invaluable tool, I use it all the time. I'd be careful how you acess raw MAPI properties if you decide you need information not available in the Outlook object model. CDO 1.21 is an optional installation in Outlook 2003 and only available via download from the MS Web site in Outlook 2007. It's also being deprecated. Extended MAPI is not supported for managed code and can only be programmed in unmanaged code using C++ or Delphi. The other ways to access MAPI properties are by using 3rd party libraries such as Redemption from the author of OutlookSpy. -- Show quoteKen Slovak [MVP - Outlook] http://www.slovaktech.com Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 Reminder Manager, Extended Reminders, Attachment Options http://www.slovaktech.com/products.htm "Ryan Taylor" <RyanTay***@discussions.microsoft.com> wrote in message news:1FF35343-A648-4B00-AE4E-FC29834CEDA8@microsoft.com... > Hi Ken, > > Thank you for your continued help! One of your suggestions appears to do > exactly what I am looking for. I starting searching for ways to access > PR_MESSAGE_FLAGS and I came across a program called OutlookSpy ( > http://www.dimastr.com/outspy/) This made it really easy to compare > different message attributes to find what was the same/different for > new/reply/forward/open messages. Per your suggestions, I started > exploring > for MSGFLAG_UNSENT. I was unable to easily find how to access the MAPI > Message object, but I did find a nice property that reflects what you were > talking about: > > MailItem myMail; > myMail.Sent property. > > This property appears to always be set to false when I am in an editable > window, and true when I have only opened the email (but not to edit). So > I > can easily check this property and remove my add-in at will (Since > everything > eventually goes through my > MSOutlook.InspectorsEvents_NewInspectorEventHandler, regardless of how the > user opened/replied/etc the email. > > So my solution was to remove the that hooked into the ActiveExplorer > events, > as well as the MailItem specific code hooking into > _mailItem.Forward/Reply/etc. I have instead replaced it with: > > private void Inspectors_NewInspector(Inspector inspector) > { > if (inspector.CurrentItem is MSOutlook.MailItem) > { > MailItem current = inspector.CurrentItem as MailItem; > if(current.Sent) > { > RemoveAddin(...); > } > } > } > > Thank you very much for your help! > > Ryan Hi Ken,
Thank you again for your help! I have done exactly as you have suggested. Initially, before I read your response I tried the approach that I described earlier, and it didn't work when the user moved between different windows (an open email, reply window, etc). Following your suggestion, I moved that logic to the inspector.Activate() event, where I could show/hide my add-in as needed whenever a given window became active/inactive which seems to work for both office 2007 and 2003. Thank you very much! Ryan Show quote "Ken Slovak - [MVP - Outlook]" wrote: > I wouldn't rely on testing for that in NewInspector, especially if your > users will be running Outlook 2007 at some point. It's a weak object > reference that you get in NewInspector and it isn't recommended to access > more than Class and MessageClasss in that event handler. I'd do it in the > first Inspector.Activate() event and that's where I'd be calling to create > the UI. Inspector.CommandBars or the Inspector Ribbon aren't guaranteed to > be instantiated until Activate() fires. > > OutlookSpy is an invaluable tool, I use it all the time. > > I'd be careful how you acess raw MAPI properties if you decide you need > information not available in the Outlook object model. CDO 1.21 is an > optional installation in Outlook 2003 and only available via download from > the MS Web site in Outlook 2007. It's also being deprecated. Extended MAPI > is not supported for managed code and can only be programmed in unmanaged > code using C++ or Delphi. The other ways to access MAPI properties are by > using 3rd party libraries such as Redemption from the author of OutlookSpy. > > -- > Ken Slovak > [MVP - Outlook] > http://www.slovaktech.com > Author: Absolute Beginner's Guide to Microsoft Office Outlook 2003 > Reminder Manager, Extended Reminders, Attachment Options > http://www.slovaktech.com/products.htm > > > "Ryan Taylor" <RyanTay***@discussions.microsoft.com> wrote in message > news:1FF35343-A648-4B00-AE4E-FC29834CEDA8@microsoft.com... > > Hi Ken, > > > > Thank you for your continued help! One of your suggestions appears to do > > exactly what I am looking for. I starting searching for ways to access > > PR_MESSAGE_FLAGS and I came across a program called OutlookSpy ( > > http://www.dimastr.com/outspy/) This made it really easy to compare > > different message attributes to find what was the same/different for > > new/reply/forward/open messages. Per your suggestions, I started > > exploring > > for MSGFLAG_UNSENT. I was unable to easily find how to access the MAPI > > Message object, but I did find a nice property that reflects what you were > > talking about: > > > > MailItem myMail; > > myMail.Sent property. > > > > This property appears to always be set to false when I am in an editable > > window, and true when I have only opened the email (but not to edit). So > > I > > can easily check this property and remove my add-in at will (Since > > everything > > eventually goes through my > > MSOutlook.InspectorsEvents_NewInspectorEventHandler, regardless of how the > > user opened/replied/etc the email. > > > > So my solution was to remove the that hooked into the ActiveExplorer > > events, > > as well as the MailItem specific code hooking into > > _mailItem.Forward/Reply/etc. I have instead replaced it with: > > > > private void Inspectors_NewInspector(Inspector inspector) > > { > > if (inspector.CurrentItem is MSOutlook.MailItem) > > { > > MailItem current = inspector.CurrentItem as MailItem; > > if(current.Sent) > > { > > RemoveAddin(...); > > } > > } > > } > > > > Thank you very much for your help! > > > > Ryan > > |
|||||||||||||||||||||||