问题
Please refer this link
Embedding a GLFW window inside windows forms
How can the same achieved by using VC++ to embed glfw window to Parent form?
回答1:
Try this:
- Call
glfwWindowHint()
to setGLFW_DECORATED
andGLFW_VISIBLE
tofalse
. - Call
glfwCreateWindow()
. - Call
glfwGetWin32Window()
to get the native handle of the OpenGL window. - Call
SetParent()
to set your form as the new parent of the OpenGL window. - Call
GetWindowLong()
/SetWindowLong()
to remove theWS_POPUP
and add theWS_CHILDWINDOW
style for the OpenGL window. - Call
ShowWindow()
to finally make the OpenGL window visible.
I got this from github.com/Chronial/foo_chronflow :: EngineWindow.cpp.
You might also call SetWindowPos()
to adjust the position of the OpenGL window within your form.
回答2:
The link in zett42's post is dead, so here's a more complete snippet
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);
来源:https://stackoverflow.com/questions/46152212/embed-windowglfwcreatewindow-as-child-to-c-mfc-parent-form