Search code examples
c#handleword-addins

WordAddIn get document handle


I need to get the Win32Window (Handle) of the current active Document.

This is what I am currently using:

NativeWindow Win32Parent = new NativeWindow()
                         .AssignHandle(Process.GetCurrentProcess().MainWindowHandle);

this works, but because of this piece of code Word does restart every time after I close it.


Solution

  • Got it. If somebody cares about the Solution:

    Control control = Control.FromHandle((IntPtr)this.Application.ActiveWindow.Hwnd);