VSTO CommandBarButton click modifier - outlook

I create a toolbar menu hierarchy in Outlook using VSTO, CommandBarPopup and CommandBarButton. I set a Click handler on the CommandBarButton's and everything works fine, but I would like to be able to do different things in the click handler depending on whether the user right-clicked on the menu, or shift-left-clicked or what not (for example, to include or not include the original message when automatically composing a template reply).
How do I detect which mouse button the user clicked with, or whether shift, alt, or ctrl keys were pressed when the user clicked?

In the event handler you can use the Keyboard.GetKeyStates method which gets the set of key states for the specified key.
// Uses the Keyboard.GetKeyStates to determine if a key is down.
// A bitwise AND operation is used in the comparison.
if ((Keyboard.GetKeyStates(Key.LeftShift) & KeyStates.Down) > 0)
{
// the left shift is pressed now
}
CommandBars were deprecated with Office 2010. You need to use the Fluent UI for creating a custom UI in the add-in. There are two main ways in VSTO to create a custom UI:
Walkthrough: Create a custom tab by using the Ribbon Designer
Walkthrough: Create a custom tab by using Ribbon XML
A context menu is customized using the Fluent UI as well. See Extending the User Interface in Outlook 2010 for more information.
The Fluent UI is described in depth in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

Related

VSTO Outlook: Detect when any Outlook backstage view overlaps the explorer or inspector window

Well, every time I need to do things in my Outlook Add-in using VSTO I always get problems, limitations, restrictions, etc.....
Having said that... Now I am trying to detect when explorer or inspector window are not visible as the topmost.
For example, I have a custom task pane which I catch any visibility change through the correspondent VisibleChanged event. This event is triggered when its visibility changes from true to false or vice versa or when the custom task pane is closed for any reason. When the custom task pane is not visible I do some stuff.
The problem I have is the following:
If I am in the explorer or inspector window and I click on the Outlook "File" tab/menu, the current view changes and the explorer and inspector are not the topmost (they are not visible) and the worst, the custom task pane VisibleChanged event is triggered.... so in this use case I do not want to do those stuffs when custom task pane is not visible. How can I detect this particular use case? I mean when explorer or inspector window are not displayed as the topmost.
You need to use backstage UI customizations where you could specify callbacks for handling the backstage open and close operations. For example, the following backstage UI XML markup declares the callback for opening the backstage UI:
<?xml version="1.0" encoding="utf-8"?>
<!-- customUI is the root tag of all Fluent UI customizations. -->
<customUI xmlns="https://schemas.microsoft.com/office/2009/07/customui"
onLoad="OnLoad">
<!—The Backstage element defines the custom structure of the Backstage UI. -->
<backstage onShow="OnShow">
So, by getting the onShow callback invoked you will be aware when the task pane is overlapped with a backstage UI in Office applications. See Adding Custom Commands and Changing the Visibility of Controls in the Office 2010 Backstage View for more information.
The backstage UI is described in depth in the Introduction to the Office 2010 Backstage View for Developers article.
FYI The Outlook object model provides the Application.ActiveWindow method which returns an object representing the current Microsoft Outlook window on the desktop, either an Explorer or an Inspector object.

VSTO Outlook: Create a custom quick access toolbar (QAT) programmatically

I have seen that Outlook has a quick access toolbar (QAT).
You can access it doing below:
And then the QAT appears (see below screenshot, I marked it with a blue rectangle):
So taken into account that a custom task pane (ctp) have some limitations, for example, you cannot remove title bar nor buttons I was thinking about if it is possible to create a QAT programmatically and embed into it an WPF user control.
Is it possible?
No, it is not possible. At least there is no trivial way of getting the job done without Windows API functions involved.
The QAT (Quick Access Toolbar) has a predefined set of controls that can be put inside it. Read more about the Fluent UI (aka Ribbon UI) in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

How to raise event from one VSTO outlook addin project and subscribe in another VSTO outlook addin Project

Can someone please please provide the link or code snippet to raise an event from the click of the oulook ribbion button and we are able to subscribe it from the another project on the click of another button and get the data passed in it.
You can't directly - ribbon control events are only passed to the addin that created the ribbon controls in question. You can of course call any external code (including through Addin.Object) from the addin processing the event.
You can handle clicks on the built-in controls on the ribbon. Read more about that in the Temporarily Repurpose Commands on the Office Fluent Ribbon article.
But for the custom ribbon UI you need to ask for any public interface which can be consumed by others, so instead of trying to repurpose controls you could directly call the method or function in the add-in.

disable outlook VSTO plugin icon

I have requirement to disable outlook vsto plugin icon if user open email from saved location . its job is to select highlighted emails from outlook and saved to external crm . There is new requirement that if email is saved on disk and re opened again it still shows the outlook plugin incon , i have to disable the incon if email is opened from disk .
any idea how to achieve this . I user select any email from outlook it should be fine but if email is saved on disk outlook addin icon should be disabled.
Many thanks
As a rule, mail items opened from the disk don't have the EntryID property set. I'd suggest starting from the NewInspector event which is fired whenever a new inspector window is opened, either as a result of user action or through program code. So, you may check whether the EntryID exists and whether item is not composed one which means newly created in Outlook. The PR_MESSAGE_FLAGS property provides flags that can be used to identify whether it is read-only or composed item.
As for the Fluent UI, you need to use the IRibbonUI.Invalidate or IRibbonUI.InvalidateControl methods. You can customize the Ribbon UI by using callback procedures in COM add-ins. For each of the callbacks the add-in implements, the responses are cached. For example, if an add-in writer implements the getImage callback procedure for a button, the function is called once, the image loads, and then if the image needs to be updated, the cached image is used instead of recalling the procedure. This process remains in-place until the add-in signals that the cached values are invalid by using the Invalidate method, at which time, the callback procedure is again called and the return response is cached. The add-in can then force an immediate update of the UI by calling the Refresh method. The getVisible callback should be used for hiding and displaying the ribbon UI dynamically.
The Fluent UI (aka Ribbon UI) is described in-depth in the following series of articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)

MS Outlook 2016 Ribbon Scaling issues

When the width of an Outlook Explorer or Inspector window is reduced the ribbon changes. In my VSTO addin can I influence how the scaling happens with the Office Ribbon?
Further at a certain width the tab becomes a single icon with a small arrow which when clicked the buttons/elements of the tab appear in a pop-up. How can I set the icon that appears in this case?
Below is my current XML for the tab.
I have also added a picture of how my ribbon looks when the window is made narrow.
I am not able to find a new XML Markup from Microsoft is this really the latest version [MS-CUSTOMUI2]: Custom UI XML Markup Version 2 Specification
<tabs>
<!-- Creates a new App Tab on the inspector toolbar-->
<tab idMso="TabReadMessage">
<group id="AppGroup" label="App">
<!-- A toggle or ON/OFF button to Encrypt or Decrypt an email and show the current encryption -->
<toggleButton id="insDecryptButton"
getLabel="insDecryptButton_getLabel"
size="large"
onAction="insDecryptButton_ButtonClick"
getImage="insDecryptButton_getImage"
getSupertip="insDecryptButton_getSupertip"
getScreentip="insDecryptButton_getScreentip"
getPressed="insDecryptButton_getPressed"
getVisible="insDecryptButton_getVisible"/>
<!-- A Button with drop down that shows all the File Numbers in the Email. If there are no file numbers this will not appear. -->
<dynamicMenu id="insMenu"
getLabel="insMenu_getLabel"
size="large"
getImage="insMenu_getImage"
getVisible="insMenu_getVisible"
getSupertip="insMenu_getSupertip"
getScreentip="insMenu_getScreentip"
getContent="insMenu_getContent"/>
<!-- Button to upload the email or attachments to IPAS -->
<dynamicMenu id="upMenu"
getLabel="upMenu_getLabel"
size="large"
getImage="upMenu_getImage"
getVisible="upMenu_getVisible"
getSupertip="upMenu_getSupertip"
getScreentip="upMenu_getScreentip"
getContent="upMenu_getContent"/>
</group>
</tab>
Office applications perform the scaling optimization on its own. There is no new schema for that. Instead, as other poster noticed, you need to provide the getImage callback to all your group controls. It should look like this:
C#: IPictureDisp GetImage(IRibbonControl control)
VBA: Sub GetImage(control As IRibbonControl, ByRef image)
C++: HRESULT GetImage([in] IRibbonControl *pControl, [out, retval] IPictureDisp ** ppdispImage)
Visual Basic: Function GetImage(control as IRibbonControl) as IPictureDisp
Calling the Invadiate or InvalidateControl you may get a new image displayed (so, your callback will be invoked).
Read more about the Fluent UI (aka Ribbon UI) in the following articles:
Customizing the 2007 Office Fluent Ribbon for Developers (Part 1 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 2 of 3)
Customizing the 2007 Office Fluent Ribbon for Developers (Part 3 of 3)
If you want to know more about dynamic customizations you may take a look at:
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 1 of 2)
OfficeTalk: Display and Hide Tabs, Groups, and Controls on the Microsoft Office Ribbon User Interface (Part 2 of 2)

Resources