Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>This is too long to post as a comment...</p> <p>I think the problem you are running in to is the way you wrapped the code I presented in the ShowDialog overload. If you follow what your <code>GetWindowFromHost</code> code is doing it goes through the following steps:</p> <ol> <li>Creates a new IntPtr from the hwnd given.</li> <li>Creates a new NativeWindow object and assigns it's handle to be the IntPtr.</li> <li>Sets the IntPtr (in the finally block) to be IntPtr.Zero.</li> </ol> <p>I think it's this finally block that is causing you problems. In my code, the finally block would run after the call to <code>this.ShowDialog(nativeWindow)</code> finished. At that point the handle (IntPtr) was no longer being used. In your code, you are returning an <code>IWin32Window</code> that should still be holding a reference to that IntPtr, which at the time you call <code>launchTarget.ShowDialog(parentWindow)</code> is IntPtr.Zero.</p> <p>Try changing your code to look like this:</p> <pre><code>private NativeWindow GetWindowFromHost(int hwnd) { IntPtr handle = new IntPtr(hwnd); NativeWindow nativeWindow = new NativeWindow(); nativeWindow.AssignHandle(handle); return window; } </code></pre> <p>And then change your calling code to look like this:</p> <pre><code>Form launchTarget = FormFactory.GetForm(xxx); // psuedo-code for generic form loaderlaunchTarget.StartPosition = FormStartPosition.CenterParent; NativeWindow parentWindow = GetWindowFromHwnd(hwnd); try { launchTarget.ShowDialog(parentWindow); } finally { parentWindow.DestroyHandle(); } </code></pre> <p>These changes should work, but again this is untested.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload