Note that there are some explanatory texts on larger screens.

plurals
  1. POShould Form.ShowDialog(IWin32Window) work with any window handle?
    primarykey
    data
    text
    <p>When using <code>System.Windows.Forms.ShowDialog(IWin32Window)</code>, should I be able to pass in an <code>IWin32Window</code> representing any window handle and have it be modal with respect to that window?</p> <p>As part of an Internet&nbsp;Explorer&nbsp;7 extension I'm trying to open a window modal with respect to an Internet&nbsp;Explorer tab. It's not the currently selected tab, but I can get the hwnd of the tab OK. However, when I pass this to ShowDialog my Form is shown, but it's not modal with respect to anything: I can still do things in Internet&nbsp;Explorer, including in the tab that's supposed to be the owner. My form is shown floating above the Internet&nbsp;Explorer windows and it stays on top, so it's not like it's just opened as a normal form, but it's not correctly modal.</p> <p>Using <a href="http://msdn.microsoft.com/en-us/library/aa264396%28v=vs.60%29.aspx" rel="nofollow noreferrer">Spy++</a>, I can find my form and it's owner handle is correctly set. </p> <p>Does this mean that something has gone wrong, or I'm doing something wrong? How do I make my form correctly modal?</p> <p>FYI, I'm using this wrapper class to create an <code>IWin32Window</code> from a <code>hwnd</code> (thanks <a href="http://ryanfarley.com/blog/archive/2004/03/23/465.aspx" rel="nofollow noreferrer">Ryan!</a>):</p> <pre><code>/// &lt;summary&gt; /// Wrapper class so that we can return an IWin32Window given a hwnd /// &lt;/summary&gt; public class WindowWrapper : System.Windows.Forms.IWin32Window { public WindowWrapper(IntPtr handle) { _hwnd = handle; } public IntPtr Handle { get { return _hwnd; } } private IntPtr _hwnd; } </code></pre> <p>UPDATE: Using Internet&nbsp;Explorer&nbsp;7 &amp; .NET 2.0</p> <p>UPDATE: Playing around some more with Spy++ and the handles it exposes, I find that if I use a different <code>hwnd</code> then I can make my window modal to the tab:</p> <p>I was using the tab's <code>hwnd</code> as suggested by the <a href="http://msdn.microsoft.com/en-us/library/aa752126(VS.85).aspx" rel="nofollow noreferrer">IWebBrowser2.HWND doc</a>, which in Spy++ appears as class <code>TabWindowClass</code>. It has a child of class <code>Shell DocObject View</code>, which has a child of Internet_Explorer_Server. If I use the <code>hwnd</code> of the <code>Internet Explorer_Server</code> then it works correctly, for example, when I click with the mouse on other tabs, Internet&nbsp;Explorer reacts normally. When I click with the mouse on the tab of interest, it plays the windows d'oh sound and doesn't do anything.</p> <p>I don't yet know how to programatically get the Internet_Explorer_Server <code>hwnd</code>, but it should be possible.</p> <p>Also, for what it's worth, while playing with other window handles I was generally able to make my form modal to other applications and dialogs. So I guess the answer to my question is 'many but not all handles'... possibly it depends on the application?</p> <p>UPDATE: Another side-note: The original reason I wanted to make my form modal to the tab instead of the whole window is that when opening a <code>MessageBox</code> from my form, passing the form as owner, the <code>MessageBox</code> would not always open on top of my form. If a new Internet&nbsp;Explorer tab had just been opened but wasn't active then the <code>MessageBox</code> would be hidden and that tab would start flashing. However, since Internet&nbsp;Explorer was disabled with my form opened modal it wasn't possible to switch to that tab, so Internet&nbsp;Explorer would be frozen. I thought that opening my form modal to the tab would solve this, but I've found another solution is to avoid using <code>MessageBox</code>: if I use a second form and <code>ShowDialog(this)</code> from my first form then the second form correctly opens to the front. So it seems that <code>Form.ShowDialog()</code> works better than <code>MessageBox.Show()</code> in some cases. More discussion in <em><a href="http://social.msdn.microsoft.com/Forums/en-US/ieextensiondevelopment/thread/df0fe7f2-0153-47d9-b18f-266d57ab7909" rel="nofollow noreferrer">Problems with modal dialogs and messageboxes</a></em>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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