将 window(glfwCreateWindow) 作为 C++ MFC 父窗体的子窗体嵌入
embed window(glfwCreateWindow) as child to C++ MFC parent form
请参考这个link
Embedding a GLFW window inside windows forms
如何使用 VC++ 将 glfw window 嵌入到父窗体来实现同样的效果?
试试这个:
- 调用
glfwWindowHint()
将 GLFW_DECORATED
和 GLFW_VISIBLE
设置为 false
。
- 呼叫
glfwCreateWindow()
.
- 调用
glfwGetWin32Window()
获取OpenGL的原生句柄window。
- 调用
SetParent()
将您的表单设置为 OpenGL 的新父级 window。
- 调用
GetWindowLong()
/ SetWindowLong()
删除 WS_POPUP
并为 OpenGL window 添加 WS_CHILDWINDOW
样式 window.
- 调用
ShowWindow()
最终使 OpenGL window 可见。
我从 github.com/Chronial/foo_chronflow :: EngineWindow.cpp 那里得到了这个。
您也可以调用 SetWindowPos()
来调整 OpenGL window 在表单中的位置。
zett42 的 post 中的 link 已经死了,所以这里有一个更完整的片段
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);
请参考这个link
Embedding a GLFW window inside windows forms
如何使用 VC++ 将 glfw window 嵌入到父窗体来实现同样的效果?
试试这个:
- 调用
glfwWindowHint()
将GLFW_DECORATED
和GLFW_VISIBLE
设置为false
。 - 呼叫
glfwCreateWindow()
. - 调用
glfwGetWin32Window()
获取OpenGL的原生句柄window。 - 调用
SetParent()
将您的表单设置为 OpenGL 的新父级 window。 - 调用
GetWindowLong()
/SetWindowLong()
删除WS_POPUP
并为 OpenGL window 添加WS_CHILDWINDOW
样式 window. - 调用
ShowWindow()
最终使 OpenGL window 可见。
我从 github.com/Chronial/foo_chronflow :: EngineWindow.cpp 那里得到了这个。
您也可以调用 SetWindowPos()
来调整 OpenGL window 在表单中的位置。
zett42 的 post 中的 link 已经死了,所以这里有一个更完整的片段
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);