本文介绍了如何将窗口所有者设置为非托管窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将所有者表单设置为一个未管理的窗口.我有非托管窗口的句柄.如何将这个非托管窗口设置为托管表单的所有者窗口?
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.
更多推荐
如何将窗口所有者设置为非托管窗口
发布评论