"share" a custom task pane between all windows of the same presentation - powerpoint

I use the below code to manage different custom task panes in PowerPoint VSTO across presentations. This works fine, e.g. when a user opens a new presentation a new task pane is created and it does not affect any other open presentation task panes.
Now I encountered the following situation. A user has opened a presentation and now opens an additional window in PowerPoint for this presentation (click "View", "New window"). Now what happens is that a new custom task pane (because this window's HWND is different) is created but instead I need this task pane to be the same as in the other presentation window.
Question: how can I "share" a task pane between all windows of the same presentation?
Dim CreatedPanes As New Dictionary(Of String, CustomTaskPane)
Public Function GetTaskPane(taskPaneId As String, taskPaneTitle As String) As Microsoft.Office.Tools.CustomTaskPane
Dim key As String = $"{taskPaneId}({Globals.ThisAddIn.Application.HWND})"
If Not CreatedPanes.ContainsKey(key) Then
Dim pane = Globals.ThisAddIn.CustomTaskPanes.Add(New myTaskPaneControl(), taskPaneTitle)
CreatedPanes(key) = pane
End If
Return CreatedPanes(key)
End Function
I think the same logic will apply to Excel as well, hence I am sldo adding this tag to the question.

is created but instead I need this task pane to be the same as in the other presentation window.
It seems you just need to implement a singleton pattern for custom task panes. I.e. share the same information for all other instances of the task pane to keep the data up to date.
PowerPoint displays each document in a different document frame window. When you create a custom task pane for these applications, the custom task pane is associated only with a specific document. If the user opens a different document, the custom task pane is hidden until the earlier document is visible again.
If you want to display a custom task pane with multiple documents, create a new instance of the custom task pane when the user creates a new document or opens an existing document. To do this, handle events that are raised when a document is created or opened, and then create the task pane in the event handlers. You can also handle document events to hide or display task panes depending on which document is visible.
To associate the task pane with a specific document window, use the Add method to create the task pane, and pass a DocumentWindow (for PowerPoint) to the window parameter.
To monitor the state of document windows in PowerPoint, you can handle the following events:
Microsoft.Office.Interop.PowerPoint.EApplication_Event.AfterNewPresentation
Microsoft.Office.Interop.PowerPoint.EApplication_Event.AfterPresentationOpen
Microsoft.Office.Interop.PowerPoint.EApplication_Event.NewPresentation
Microsoft.Office.Interop.PowerPoint.EApplication_Event.PresentationOpen
Microsoft.Office.Interop.PowerPoint.EApplication_Event.WindowActivate
Microsoft.Office.Interop.PowerPoint.EApplication_Event.WindowDeactivate

Related

VSTO Outlook: How to know if the window being opened is the compose window

I have an scenario in which I need to know if the window being opening is the compose window (that opened when you click on New mail). How can I do it?
Check the value of the Inspector.CurrentItem.Sent property. Make sure Inspector.CurrentItem is actually a MailItem object first.
One way you can do it is by using a FormRegion, which has a FormRegionMode property.
That property holds a OlFormRegionMode enumeration value that is set by Outlook based on whether the window is in reading, compose or preview (in-line reading pane) mode.

Open Task pane from command in Outlook add-in using Office.js

I am working on an outlook add-in and I need the ability to open a task pane from one of the button commands.
Long story short the command will reach out to an API. The result of the API call will let the client side know if any user interaction is required. If it is I want to present the user with the task pane to fill in any required information.
From what I have found you should be able to call Office.addin.showAsTaskpane().
However this only works if you are using the Shared runtime requirement set which is only supported in Powerpoint, Word, and Excel.
In Outlook you can open a task pane by clicking on the ribbon button or notification item which can be added programmatically, i.e. dynamically. So, you may consider adding a notification item with a link for opening a task pane as a possible workaround. However, it requires a user interaction.
Web add-ins don't provide any way in Outlook to open a task pane programmatically. You can file a new feature request at https://aka.ms/M365dev-suggestions .
This is not supported yet
You can refer from here Duplicate question OR similar
Thanks

MS Office: drag and drop outlook item into a shortcut to run it

I would like to be able to drag and drop a Microsoft Office Outlook item into a non-running application or a shortcut: the application must start with the dropped item as start item, without first running the application and then, in another step dropping the item.
By default, looks like to drop Outlook Items into a user application (or shortcut link) is not enabled, like for notepad, explorer and other Microsoft applications. Maybe there is a registry setting required to define that capability for a user application.
To test, drag-and-drop any item from Outlook into a dormant Notepad (or .txt file), word, excel or desktop, the item will generate action from the application (create a shortcut or open de app). With some others, including your own, the drag-and-drop fail.
To start an application, with a random (disk) file as parameter, from 'explorer', drag-and- drop a regular file into the shortcut (or the .exe): the program is run as xxxx.exe "%1"where %1 will be the file location; how can we do the same dragging from outlook?
Dropping outlook items into a running application is straightforward: on the application drag-over event you determine the kind of item looking at the clipboard Data.GetFormats and then, either open the file or use the outlook 'inspector' to get the item.

save the action performed by context menu in vb.net forms app on pc reboot

I have made a vb.net app which hides the utorrent and other less usable icons from tray. I used to fetch these icons in a listview in vb.net and on right clicking the program name, there appears a context menu which hides the icon. But after rebooting the system the icon appears again. Is there any way to save the event in mysettings.settings so that rebooting doesn't affect the action taken... here's my code
Public Shared Sub hideTaskbarIcons(hide As Boolean, indexcnt As Integer)
buttonsOverflow = GetButtons(hwndOverflow)
SendMessage(FindTrayToolbarWindowOverflow, TB_HIDEBUTTON, indexcnt, hide)
end sub
The My.Settings object is for settings that are defined at build-time (such as the state of the application's own notification icon, for instance). Since you want to store the state of a variable number of application icons, you're better off with manually reading and writing an XML document with the System.Xml namespace. You could also store the states in the registry with the Microsoft.Win32.Registry class.
Either of those options will free you from the constraints of the application settings system.

Call event in Excel VBA when switching to another app

I'm looking for an event which gets called when the user switches to another app (without closing Excel) and when he switches back to Excel again. I need to know this to stop a timer triggered event which isn't necessary when app isn't active or nothing is changed.
I would use it to implement an autosave-method which shouldn't save the file if its in the background and therefore not been changed.
There's an excellent article on how to find what events are available here
http://www.cpearson.com/excel/Events.aspx
"Open the Object Browser in the VBA Editor (press F2 or choose Object Browser from the View menu. In the Classes list, scroll down and select Worksheet. Right-click anywhere in the primary window and choose Group Members on the pop up menu. Then scroll down in the Members Of "Worksheet" list until you see items with yellow lightening bolts next to them. These are the events for the Worksheet objects. Do the same for the Workbook and Application objects."
I am not sure whether you will be able to find EXCEL events that capture your needs, as jumping to another application is not an EXCEL mechanism, but a general Windows mechanism. In fact you try to capture a kind of "LostFocus" event of the Excel application itself. Excel however gives you only event triggers for events that are "local to the Excel application".
What about calling your external program by pressing an Excel Button which contains code to
set a global status variable to "I JUMPED OFF"
stop the timer
start the external application (Shell or similar), minimize the window or whatever
plus a global Selection_Change trigger that
examines the status variable, and if it was set to "I JUMPED OFF"
set it back to "I AM HERE"
restart the timer
Of course this is a bit weak and the user can trick you out by simply manoevering with the mouse or Alt-TAB, but if you maximize the window on Startup you can motivate the user to use the Buttons.

Resources