none
Office window loses focus when win form closes RRS feed

  • Question

  • I have a VSTO Excel add-in which works on Office 2007-2013 and Windows XP to 8. The add-in shows a Windows form which sits over the Excel window. The window TopMost property is set to false but the window's owner is the Excel application window so that it doesn't disappear if the user clicks in the worksheet. This is done by using a class to implement IWin32Window

    Public Class OfficeAppWindow
            Implements Windows.Forms.IWin32Window

            Private winHandle As IntPtr

            Public Sub New(hwnd As IntPtr)
                winHandle = hwnd
            End Sub

            Public ReadOnly Property Handle As IntPtr Implements Windows.Forms.IWin32Window.Handle
                Get
                    Return winHandle
                End Get
            End Property
    End Class

    and the form is shown like this:

    theForm.Show(New OfficeAppWindow(Globals.ThisAddIn.Application.Hwnd))

    This displays fine but the problem is that when the form closes, the Excel window loses focus to the next window in the windows Z-Order which could be any other random application running. I've tried trapping the form's FormClosed event and running Globals.ThisAddIn.Application.ActiveWindow.Activate but it makes no difference. This seems to be a problem on Office 2010 with Windows 7 or Vista but I've not tested any other versions.

    Anyone got any ideas?

    Pete

    Wednesday, June 26, 2013 1:37 PM

All replies

  • Hi Xenacode,

    Thank you for posting in the MSDN Forum.

    I'm trying to involve some senior engineers into this issue and it will take some time. Your patience will be greatly appreciated.

    Sorry for any inconvenience and have a nice day!

    Best regards,


    Quist Zhang [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, June 27, 2013 11:45 AM
    Moderator
  • Hi Pete,

    Please consider my apologies, I read the post too quickly. let me work on this and I will get back to you.

    Regards

    Sidharth

    Monday, September 2, 2013 9:37 PM