如何将窗口所有者设置为非托管窗口 [英] How to set window owner to an unmanaged window

查看:81
本文介绍了如何将窗口所有者设置为非托管窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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()

推荐答案

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

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.

这篇关于如何将窗口所有者设置为非托管窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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