2

如何在 Windows 窗体中显示过剩窗口?

glutCreateWindow("Example") 创建另一个表单,

glutCreateSubWindow(hwnd, 0, 0, 100, 100),其中 hwnd 是我在 C# 中的主窗口窗体的句柄,我得到一个 AccessViolation 异常。

Glut 程序位于 C++ DLL 中。我的应用程序在 C# WPF 上。我需要在我的 C# 表单中显示过剩视图

C++ 代码:

extern "C"
    {
        __declspec(dllexport) int InitGlut(int hwnd, int top, int left, int width, int height)
        {
            glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA);
            glutInitWindowPosition(top,left);
            glutInitWindowSize(320,320);
            //glutCreateWindow("Example");
            glutCreateSubWindow(hwnd, top, left, width, height);
            glutDisplayFunc(renderScene);
            glutMainLoop();
            return 0;
        }
    }

C#代码:

const string pathToDll = "../../../Release/MyDLL.dll";
[DllImport(pathToDll)]
public static extern int InitGlut(IntPtr hwnd, int top, int left, int width, int height);

private void Window_Loaded(object sender, RoutedEventArgs e)
{
     IntPtr hwnd = new WindowInteropHelper(Application.Current.MainWindow).Handle;
     InitGlut(hwnd, 0, 0, 100, 100);
}
4

1 回答 1

1

看起来您在 WPF 表单中托管 Win32 对象。是的,这需要解决方法。

你看过 MSDN 上的 WPF 和 Win32 互操作指南吗?

http://msdn.microsoft.com/en-us/library/ms742522.aspx

您还需要查看 HwndHost 类:

http://msdn.microsoft.com/en-us/library/system.windows.interop.hwndhost.aspx

于 2011-04-21T20:55:53.743 回答