如何将窗口所有者设置为非托管窗口

编程入门 行业动态 更新时间:2024-10-23 13:35:26
本文介绍了如何将窗口所有者设置为非托管窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想将所有者表单设置为一个未管理的窗口.我有非托管窗口的句柄.如何将这个非托管窗口设置为托管表单的所有者窗口?

I want to set the owner form to that of an unamanged window. I have the unmanaged window's handle. How can I set this unmanaged window to be the owner window for my managed form?

IntPtr hWnd = GetUnmanagedWindow();//assume the handle is returned correctly Form form = new Form(); form.Show(ConvertToManaged(hWnd));//Need an implementation for ConvertOrSomething()

推荐答案

执行此操作的标准方法是使用 NativeWindow 类.

The standard way to do this is to use the NativeWindow class.

IntPtr hWnd = GetUnmanagedWindow();//assume the handle is returned correctly Form form = new Form(); NativeWindow nativeWindow = new NativeWindow(); nativeWindow.AssignHandle(hWnd); form.Show(nativeWindow);

正如汉斯(Hans)所指出的那样,记住在完成处理后再呼叫ReleaseHandle.

As Hans points out, remember to call ReleaseHandle when are done with it.

更多推荐

如何将窗口所有者设置为非托管窗口

本文发布于:2023-11-12 03:47:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1580423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   所有者   设置为   如何将

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!