How do I replace a custom task pane in Outlook (VSTO)? - outlook

Background
Let's say I have a custom task pane like the one in the image below.
For my app, I only display this pane if the user is logged in (determined by the presence of a valid session token that was granted from an API endpoint), otherwise I display a log-in pane.
If the user leaves an inspector open when the session times out, I need to show a different task pane with a log in button. The user have many inspectors (and, therefore, many custom task panes) open at once.
I am planning to run a recursive method on a background thread about once per hour to check if the session is valid and, if not, swap any custom task panes that are displayed with a log-in pane.
Question
How do I accomplish a "swap" in each inspector the user has opened? Should I iterate all inspectors? If so, how do I access a collection of custom task panes within that inspector. Conversely, if I should iterate Globals.ThisAddIn.CustomTaskPanes, how do I identify the inspector it belongs to so that I can swap any visible custom task pane with my log-in pane?
Thanks in advance.

You need to keep a dictionary where the key will be an inspector object. So, that you can get access to the custom task pane easily.
InspectorWrapper inspectorWrapper = Globals.ThisAddIn.InspectorWrappers[inspector];
CustomTaskPane taskPane = inspectorWrapper.CustomTaskPane;
if (taskPane != null)
{
taskPane.Visible = false;
}
Take a look at the following articles for more information:
Walkthrough: Displaying Custom Task Panes with E-Mail Messages in Outlook
How to: Display Custom Task Panes with E-Mail Messages in Outlook

Related

PidlidPrivate in MAPI will not hide the message

I am checking PidlidPrivate property in MAPI.
Based on https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidlidprivate-canonical-property, this property can hide the message.
So I use MFCMAPI to set the value of PidlidPrivate property to True. But that does not work. The message will always show.
I test in Outlook 2019.
No, the message will not be hidden. It is only applicable to appointments from other user's calendars - if an appointment is marked as private, Outlook won't show its details (only start/duration). All of its properties are still accessible through MAPI.
If you want a message to be invisible to an end user, create a hidden (associated) item. Outlook Object Model exposes messages like that through MAPIFolder.GetStorage. You can see these messages in OutlookSpy (I am its author) if you click IMAPIFolder button and go to the "Associated Contents" tab. It will also let you edit MAPI properties (click IMessage button, double click on a property, etc.)

Outlook VSTO - ActiveInspector returns the incorrect contact window's information

Globals.ThisAddIn.Application.Explorers.NewExplorer += new ExplorersEvents_NewExplorerEventHandler(DoNewExplorer);
I am trying to get the information from an email that I previously opened (by double-clicking) in outlook.
The code works fine until I open multiple emails. What I am finding is that when I click on an email, the inspector activates, but I am getting the information from the last active window, not the current one that I clicked on.
In the Activate event handler you can always call the ActiveInspector method of the Outlook Application class.
Note, the Inspectors collection contains all opened inspector windows, so you could get all of them or find the required one.
Firstly, your code tracks the Explorers.NewExplorer event, not Inspectors.NewInspector.
Secondly, for the Inspectors.NewInspector event, make sure you are using the Inspector object passed to your event handler rather than Application.ActiveInspector: by the time Inspectors.NewInspector event fires, the inspector might not yet be visible/active.

Add a close button for a task module in ms teams

I am investigating if it's applicable to have a cancel/ close button on our html page inside taskmodule so it can actually close the task module?
Yes, it's entirely possible to do this. Basically, in order to close your task module in any way, you make a call from within the web page (in script), to:
microsoftTeams.tasks.submitTask
submitTask takes two parameters. The first is any object you want to return back to the caller (whatever opened your task module). For instance, if you have a Tab in your app, and the Tab opens the task module to app a new entry to a database, you could pass that new item back to the opening Tab by passing it as microsoftTeams.tasks.submitTask(newItem);
You can see more about this here.
If you have nothing at all to send back, you can simply call microsoftTeams.tasks.submitTask(null);. In this case, it will do nothing but close the task module, which sounds like what you're trying to do.

How to intercept events from specific windows in OSX

I want to have the following workflow:
User presses hotkey, or status bar menu button
User clicks on a window
Window is now "registered" in my app
App intercepts mouse events from all registered windows
I've read a lot on CGEvents, CGEventTaps and NSEvents. I can intercept global events and post new ones using CGEvents and CGEventTaps but there is not window information like windowNumber in NSEvent, only PSD (and I'm not sure how to use those), so I can't filter out events from non-registered windows. NSEvent, on the other hand, doesn't let me to intercept global events, only local ones through a localMonitor.
How could I achieve the desired functionality?
You can use the Mac OS X Accessibility API to get details about the currently focused window or application.
The UIElementInspector Apple Sample Code gives many examples.
// Given a uiElement and its attribute, return the value of an accessibility object's attribute.
+ (id)valueOfAttribute:(NSString *)attribute ofUIElement:(AXUIElementRef)element;
Use the kAXFocusedApplicationAttribute or kAXFocusedWindowAttribute attributes with valueOfAttribute:ofUIElement: to get the window/app when you "register" it with your app.
When a CGEvent comes in, compare the currently focused window/app to your list of registered windows/apps to determine if the event should be intercepted.

Get Selected attachment in outlook

I am using an addin which enable me to attach a context menu to outlook attachments. So when ever I click on an attachment I am able to see my custom button in the context menu .
The problem I am facing is, how do I know which attachment is clicked. I have some alternatives in my mind
When context menu is opening, I can associate a tag to this context menu. In this tag , i can store the file name of the attachment. Using this file name I can identify the attachment in context_menu_button_click event. Currently I cannot find a place where context menu tells about the object, on which context menu was opened.
I loop through some property available in inspector or any other object which tell me which object, inside the email is selected. For this, I can get to the selected email and I can also iterate through all attachments, but I cannot figure out which attachment is selected (or right clicked)
Thanks to this SO post
var attachmentSelection = (control.Context as AttachmentSelection).OfType<Attachment>();
Which can be translated into...
AttachmentSelection attachmentSelection = control.Context as AttachmentSelection;
Now using attachmentSelection object may solve the problem....!
Use Explorer/Inspector.AttachmentSelection collection.

Resources