2011-05-03 60 views
0

我使用VSTO自動化PowerPoint 2010中,我要檢查,如果SlideShowWindow是調用它的方法之前可用。如何測試對於PowerPoint SlideShowWindow對象?

此刻我正在捕獲COMException訪問時返回;

Globals.ThisAddIn.Application.ActivePresentation.SlideShowWindow 

完整方法是;

private SlideShowWindow GetSlideShowWindow() 
{ 
    //attempt to get the running slide show window... 
    SlideShowWindow slideShowWindow = null; 
    try 
    { 
     //try to access the COM wrapper... 
     slideShowWindow = Globals.ThisAddIn.Application.ActivePresentation.SlideShowWindow; 
    } 
    catch (COMException) 
    { 
     //window doesn't exist!... 
    } 

    //return window or null... 
    return slideShowWindow; 
} 

似乎應該有一個枚舉或標誌在對象模型中的某個地方,可以避免這種做法?

+0

如果您使用的是ppt 2010,您爲什麼不僅僅是針對openXML功能進行編程? – Avitus 2011-05-03 21:45:58

+0

實際上,我主持一個PowerPoint內WCF REST服務加載項,將響應REST調用。這是一款支持函數來獲取'SlideShowWindow'這樣的服務電話就可以開始,前進,結束,出口滑梯等會OpenXML功能允許這種應用? – SimonM 2011-05-03 22:06:57

回答

0

不知道怎麼樣打開XML註釋左右,這是一個未渲染內容操縱的工具。你想要做的是正確地假設被對象模型編程。

這裏是我會做:

Public Sub SeeIfAShowIsRunning() 
    If SlideShowWindows.Count > 0 Then 
     Debug.Print "yep, something is there. Let me check further." 
     If SlideShowWindows.Count > 1 Then 
     Debug.Print "uh huh, there are " & SlideShowWindows.Count & " shows running" 
     Debug.Print "hold on, i'll figure this out for you" 
      For i = 1 To SlideShowWindows.Count 
       If ActivePresentation.Name = Presentations.Item(i).Name Then 
        Debug.Print "i found you. your name is: " & ActivePresentation.Name 
       Else 
        Debug.Print Presentations.Item(i).Name & " is a fine pptx, but not the one i want" 
       End If 
      Next 
     End If 
    Else 
     Debug.Print "nope, you're in editing mode" 
    End If 
End Sub 

這將在PowerPoint中的所有版本。在PowerPoint 2010中,您可以在技術上有一個以上的幻燈片放映窗口中運行,但其中只有一個是積極的,所以我就做了積極的一個進一步的搜索,並得到它的.Presentation,如果它匹配ActivePresentation,那麼它就是你的正在運行的ActivePresentation幻燈片放映,如上所述。

如果您使用PowerPoint 2007或以下,那麼這是不是一個問題,你可以刪除If SlideShowWindows.Count > 1 Then聲明。

+0

啊!謝謝你,我完全錯過了'SlideShowWindows'集合。 – SimonM 2011-05-05 12:44:20