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

请参考此链接

Embedding a GLFW window inside windows forms

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

【问题讨论】:

    标签: opengl visual-c++ mfc glfw


    【解决方案1】:

    试试这个:

    1. 调用glfwWindowHint()GLFW_DECORATEDGLFW_VISIBLE设置为false
    2. 致电glfwCreateWindow()
    3. 调用glfwGetWin32Window() 获取OpenGL 窗口的本机句柄。
    4. 调用 SetParent() 将您的表单设置为 OpenGL 窗口的新父级。
    5. 调用GetWindowLong() / SetWindowLong() 删除WS_POPUP 并为OpenGL 窗口添加WS_CHILDWINDOW 样式。
    6. 调用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);
    

    【讨论】:

    • 谢谢,我也修复了链接。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 2013-07-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-29
    相关资源
    最近更新 更多