积极答复者
如何将WinForm窗口的拥有者设定为WPF窗口

问题
答案
-
参考下面代码:
[DllImport("user32.dll")] private static extern int SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong); /// <summary> /// sets the owner of a System.Windows.Forms.Form to a System.Windows.Window /// </summary> /// <param name="form"></param> /// <param name="owner"></param> public static void SetOwner(System.Windows.Forms.Form form, System.Windows.Window owner) { WindowInteropHelper helper = new WindowInteropHelper(owner); SetWindowLong(new HandleRef(form, form.Handle), -8, helper.Handle.ToInt32()); }
best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年11月16日 9:23
-
感谢回复,也许你写的代码哪里有错误,没有测试成功,不过,我已解决此问题,非API方法,参考网上示例.
另外,我曾经试用过另外的API,但是变成了MDI了,非想要效果.
- 已标记为答案 Sheldon _XiaoModerator 2011年11月16日 9:23
全部回复
-
参考下面代码:
[DllImport("user32.dll")] private static extern int SetWindowLong(HandleRef hWnd, int nIndex, int dwNewLong); /// <summary> /// sets the owner of a System.Windows.Forms.Form to a System.Windows.Window /// </summary> /// <param name="form"></param> /// <param name="owner"></param> public static void SetOwner(System.Windows.Forms.Form form, System.Windows.Window owner) { WindowInteropHelper helper = new WindowInteropHelper(owner); SetWindowLong(new HandleRef(form, form.Handle), -8, helper.Handle.ToInt32()); }
best regards,
Sheldon _Xiao[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
- 已标记为答案 Sheldon _XiaoModerator 2011年11月16日 9:23
-
感谢回复,也许你写的代码哪里有错误,没有测试成功,不过,我已解决此问题,非API方法,参考网上示例.
另外,我曾经试用过另外的API,但是变成了MDI了,非想要效果.
- 已标记为答案 Sheldon _XiaoModerator 2011年11月16日 9:23