将窗口(glfwCreateWindow)作为子嵌入到 C++ MFC 父窗体

Posted

技术标签:

【中文标题】将窗口(glfwCreateWindow)作为子嵌入到 C++ MFC 父窗体【英文标题】:embed window(glfwCreateWindow) as child to C++ MFC parent form 【发布时间】:2017-09-11 09:21:53 【问题描述】:

请参考此链接

Embedding a GLFW window inside windows forms

如何使用VC++将glfw窗口嵌入到Parent窗体中?

【问题讨论】:

【参考方案1】:

试试这个:

    调用glfwWindowHint()GLFW_DECORATEDGLFW_VISIBLE设置为false。 致电glfwCreateWindow()。 调用glfwGetWin32Window() 获取OpenGL 窗口的本机句柄。 调用 SetParent() 将您的表单设置为 OpenGL 窗口的新父级。 调用GetWindowLong() / SetWindowLong() 删除WS_POPUP 并为OpenGL 窗口添加WS_CHILDWINDOW 样式。 调用ShowWindow() 最终使OpenGL 窗口可见。

我是从 github.com/Chronial/foo_chronflow :: EngineWindow.cpp 那里得到的。

您也可以调用 SetWindowPos() 来调整 OpenGL 窗口在表单中的位置。

【讨论】:

我会实施你的方法并更新你。这正是我想要的 收到错误消息“glfwGetWin32Window()”未定义。我尝试在#include 之后包含#include 但没有运气。我需要定义任何特定的宏吗? 我已经包含了#define GLFW_EXPOSE_NATIVE_WGL #define GLFW_EXPOSE_NATIVE_WIN32,现在看起来还可以 @LittleQuest 太好了。如果此答案对您有用,请单击复选标记按钮接受。 :当然。我确信这个方法会起作用,但 glfwGetWin32Window 返回 NULL。试图找出问题所在。【参考方案2】:

zett42 帖子中的链接已经失效,所以这里有一个更完整的 sn-p

glfwWindowHint(GLFW_DECORATED, GLFW_FALSE);
glfwWindowHint(GLFW_VISIBLE, GLFW_FALSE);

GLFWwindow* pWindow = glfwCreateWindow(width, height, "", NULL, NULL);

HWND hwNative = glfwGetWin32Window(m_pWindow);

SetParent(hwNative, hwParentWindow);

long style = GetWindowLong(hwNative, GWL_STYLE);
style &= ~WS_POPUP; // remove popup style
style |= WS_CHILDWINDOW; // add childwindow style
SetWindowLong(hwNative, GWL_STYLE, style);

... any other initialisation code (e.g enable/disable gl features) ...

ShowWindow(hwNative, SW_SHOW);

【讨论】:

谢谢,我也修复了链接。

以上是关于将窗口(glfwCreateWindow)作为子嵌入到 C++ MFC 父窗体的主要内容,如果未能解决你的问题,请参考以下文章

glfwCreateWindow返回NULL问题

glfwCreateWindow 在 Mac OS 上返回 NULL

OpenGL 上下文存储在哪里?

OpenGL imgui 滑块范围

如何定义 QT Opengl 帧缓冲区的大小

将当前窗口作为CommandParameter传递