应该Form.ShowDialog(IWin32Window)与任何窗口句柄工作? [英] Should Form.ShowDialog(IWin32Window) work with any window handle?

查看:2237
本文介绍了应该Form.ShowDialog(IWin32Window)与任何窗口句柄工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 System.Windows.Forms.ShowDialog(IWin32Window),我应该能够在 IWin32Window 代表任何窗口句柄,并将它是模态的相对于该窗口

When using System.Windows.Forms.ShowDialog(IWin32Window), should I be able to pass in an IWin32Window representing any window handle and have it be modal with respect to that window?

作为Internet&NBSP的一部分; NBSP浏览器&; 7扩展我试图打开一个窗口模式相对于互联网 浏览器选项卡。这不是当前选中的标签,但我可以得到标签OK的HWND。然而,当我把它传递给我的ShowDialog窗体显示,但它不是针对任何模态:我还可以做的事情在Internet 浏览器,包括那些应该是主人的标签。显示我的形式漂浮在互联网&NBSP以上;资源管理器窗口,并停留在上面,所以它不喜欢它只是打开了作为一个正常的形式,但它不是正确的模式。

As part of an Internet Explorer 7 extension I'm trying to open a window modal with respect to an Internet 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 Explorer, including in the tab that's supposed to be the owner. My form is shown floating above the Internet 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.

使用间谍++ ,我能找到我形式和它的主人手柄设置是否正确。

Using Spy++, I can find my form and it's owner handle is correctly set.

这是否意味着出了问题,还是我做错了什么?如何让我的形式正确的模态?

Does this mean that something has gone wrong, or I'm doing something wrong? How do I make my form correctly modal?

通知你,我用这个包装类来创建一个 IWin32Window HWND (感谢的瑞安):

FYI, I'm using this wrapper class to create an IWin32Window from a hwnd (thanks Ryan!):

/// <summary>
/// Wrapper class so that we can return an IWin32Window given a hwnd
/// </summary>
public class WindowWrapper : System.Windows.Forms.IWin32Window
{
    public WindowWrapper(IntPtr handle)
    {
        _hwnd = handle;
    }

    public IntPtr Handle
    {
        get { return _hwnd; }
    }

    private IntPtr _hwnd;
}



更新:使用Internet&NBSP;&浏览器NBSP; 7安培; .NET 2.0

UPDATE: Using Internet Explorer 7 & .NET 2.0

更新:周围的一些更多的间谍++和它暴露了手柄玩,我发现,如果我使用不同的 HWND 然后我可以让我的窗口模式的标签:

UPDATE: Playing around some more with Spy++ and the handles it exposes, I find that if I use a different hwnd then I can make my window modal to the tab:

我使用该标签的 HWND 作为由 IWebBrowser2.HWND文档,其中建议在间谍++显示为类 TabWindowClass 。它具有类贝壳DocObject的视图的孩子,其中有Internet_Explorer_Server的孩子。如果我使用 HWND 互联网Explorer_Server 然后它工作正常,例如,当我用鼠标点击其他选项卡,互联网&NBSP;浏览器正常反应。当我感兴趣的标签上点击鼠标,它扮演的窗户德哦健全,没有做任何事情。

I was using the tab's hwnd as suggested by the IWebBrowser2.HWND doc, which in Spy++ appears as class TabWindowClass. It has a child of class Shell DocObject View, which has a child of Internet_Explorer_Server. If I use the hwnd of the Internet Explorer_Server then it works correctly, for example, when I click with the mouse on other tabs, Internet 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.

我还不知道如何编程获得Internet_Explorer_Server HWND ,但它应该是可能的。

I don't yet know how to programatically get the Internet_Explorer_Server hwnd, but it should be possible.

此外,对于它的价值,同时与打其他的窗口句柄我通常能够使我的表格模式到其他应用程序和对话框。所以我想回答我的问题是很多,但不是所有的句柄......可能这取决于应用程序

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?

更新:另一个侧面说明:原原因我想使我的窗体模态的标签,而不是整个窗口是打开一个的MessageBox 从我的形式,传递的形式为车主,<$ C $时C>的MessageBox 并不总是对我的窗体的顶部开放。如果一个新的Internet&NBSP;浏览器选项卡刚刚被打开,但没有主动再的MessageBox 将被隐藏,该选项卡将开始闪烁。然而,由于互联网&NBSP;浏览器禁用了我的形式打开模态,不可能切换到该选项卡中,因此Internet&NBSP;浏览器将被冻结。我以为我开模形式的标签会解决这个问题,但我发现另一种解决方案是避免使用的MessageBox :如果我使用第二种形式和的ShowDialog(本)从我的第一个表格,然后第二种形式正确打开到前面。如此看来, Form.ShowDialog()作品比 MessageBox.Show()在某些情况下更好。在的 问题的详细讨论与模态对话框提示消息和

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 MessageBox from my form, passing the form as owner, the MessageBox would not always open on top of my form. If a new Internet Explorer tab had just been opened but wasn't active then the MessageBox would be hidden and that tab would start flashing. However, since Internet Explorer was disabled with my form opened modal it wasn't possible to switch to that tab, so Internet 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 MessageBox: if I use a second form and ShowDialog(this) from my first form then the second form correctly opens to the front. So it seems that Form.ShowDialog() works better than MessageBox.Show() in some cases. More discussion in Problems with modal dialogs and messageboxes.

推荐答案

您的代码是正确的。你很可能遇到了,虽然问题是,IE浏览器与它的选项卡的线程模型。我不知道确切的细节,但短版本是,每个标签可以和有可能是在不同的线程比其他选项卡上运行。

Your code is correct. The problem you are likely running into though is that IE has a threading model related to its tabs. I don't know the exact details but the short version is that each tab can and likely is running on a different thread than other tabs.

对话框的Modal'ness是特定于对话框正在运行的线程。对其他线程的用户界面将是另一个线程模型对话框不受影响。这是完全有可能的,你都可以访问它运行的是标签在不同的线程这个原因。

The Modal'ness of a dialog is specific to the thread where the dialog is running. UI on other threads will be unaffected by a model dialog on another thread. It's entirely possible you are able to access tabs which are running on a different thread for this reason.

这篇关于应该Form.ShowDialog(IWin32Window)与任何窗口句柄工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆