我使用下面的代码跨演示文稿管理 PowerPoint VSTO 中的不同自定义任务窗格。这很好用,例如当用户打开一个新的演示文稿时,会创建一个新的任务窗格,并且它不会影响任何其他打开的演示文稿任务窗格。
现在我遇到了以下情况。用户打开了一个演示文稿,现在在 PowerPoint 中为此演示文稿打开了一个附加窗口(单击“查看”、“新窗口”)。现在发生的情况是创建了一个新的自定义任务窗格(因为此窗口的 HWND 不同),但我需要此任务窗格与其他演示窗口中的相同。
问题:如何在同一演示文稿的所有窗口之间“共享”任务窗格?
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
我认为同样的逻辑也适用于 Excel,因此我会将此标签添加到问题中。