embed window(glfwCreateWindow) as child to C++ MFC parent form

六眼飞鱼酱① 提交于 2021-01-24 12:24:37

问题


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:

  1. Call glfwWindowHint() to set GLFW_DECORATED and GLFW_VISIBLE to false.
  2. Call glfwCreateWindow().
  3. Call glfwGetWin32Window() to get the native handle of the OpenGL window.
  4. Call SetParent() to set your form as the new parent of the OpenGL window.
  5. Call GetWindowLong() / SetWindowLong() to remove the WS_POPUP and add the WS_CHILDWINDOW style for the OpenGL window.
  6. 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!