我想创build使用C#
窗口与设置的父到我定义的句柄,这是一个其他的过程窗口句柄。
有人知道怎么做吗?
问候,
如果我正确地理解了你的问题,你应该能够通过使用这样的东西来实现你想要的:
class Win32Window : IWin32Window { IntPtr handle; public Win32Window(IntPtr handle) { this.handle = handle; } public IntPtr Handle { get { return this.handle; } } } static void Main() { IntPtr targetParent = // Get handle to the parent window new MainForm().ShowDialog(new Win32Window(targetParent)); }
这将使MainForm
成为指定窗口的子窗口,使其始终显示在其上方。 在示例中我使用ShowDialog
,但是这也适用于Show
。 这是Windows窗体特定的。
在WPF中,您可以尝试以下操作:
var helper = new WindowInteropHelper(/* your Window instance */); helper.Owner = // Set with handle for the parent
在显示WPF窗口之后,我很快尝试了这个功能,而且看起来像预期的那样工作,但是WPF的知识并不是那么好。
我相信句柄将是只读的; 因此.Parent
属性是只读的。 不过, .Owner
属性有一个getter和一个setter( 参考MSDN )…但是,您必须有一个对父窗口的引用。
没有更多的信息,我将无法提供更多的东西。
如果您的家长候选人是非托管窗口,请检查此链接 。