Search code examples
.netvbapowerpointvsto

How to detect if user is interacting with "File Tab" in PowerPoint?


I am looking for a way to determine when a user clicks the "File Tab" (and potentially any of the sub tabs marke the following dialog is shown in PowerPoint (see screenshot).enter image description here

I tried checking the ActiveWindow.ViewType but it does not change when the user opens the dialog. I also tried checking the Panes for their respective "Active" Property but it also does not change when the user is on this screen.

I also tried this code, but to no avail.

    <DllImport("user32.dll")>
    Private Shared Function GetForegroundWindow() As IntPtr
    End Function

    If GetForegroundWindow() <> Globals.ThisAddIn.Application.HWND Then
         Exit Function
    End If

I noticed that Keyboard input is not possible while this dialog is shown but I don't know how to check this within a VSTO solution. User32 IsWindowEnabled() returns True when the dialog is shown.

Any ideas? Thanks


Solution

  • The Backstage UI provides two callbacks you are interested in:

    • onShow
    VBA: Sub OnShow(contextObject As Object)
    C#: void OnShow(object contextObject)
    Visual Basic: Sub OnShow(contextObject As Object)
    C++: HRESULT OnShow([in] Object *pContextObject)
    
    • onHide
    VBA: Sub OnHide(contextObject As Object)
    C#: void OnHide(object contextObject)
    Visual Basic: Sub OnHide(contextObject As Object)
    C++: HRESULT OnHide([in] Object *pContextObject)
    

    Read more about that in the Introduction to the Office 2010 Backstage View for Developers article.