How to get IWin32Window for Show/ShowDialog in Excel

Excel exposes the window handle of the application via the Hwnd property.  It is returned as an integer, so you will need to wrap an IntPtr around it in order to use it.

Form form = new Form();

NativeWindow xlMain = new NativeWindow();

xlMain.AssignHandle(new IntPtr(Application.Hwnd));

form.ShowDialog(xlMain);

form.Dispose();

xlMain.ReleaseHandle();

 

FROM:

http://social.msdn.microsoft.com/forums/en-US/vsto/thread/2498af9b-2172-43cf-8616-1863f293ccb8/

posted @ 2013-03-10 21:18  I'm CY  阅读(284)  评论(0编辑  收藏  举报