Attach A GLFWwindow To Windows Window Client Area?

I know this is old but will explain how I did it for those who also had issues.

BEFORE you #include your glfw includes, define the native win32 glfw exposure such as:

#define GLFW_EXPOSE_NATIVE_WIN32
#include <GLFW/glfw3.h>
#include <GLFW/glfw3native.h>

Next, make sure to include the glfw3native.h as shown above. Clean and rebuild and you should then have access to the function “HWND glfwGetWin32Window(GLFWwindow *window)” which returns a HWND handle from your GLFWwindow

Next, create a static control or dialog to use as the parent.

Somehwere in your code after both the control/dialog and GLFWwindow have been instanciated get the HWND handle and change its style to be a chiild as follows:

DWORD style = GetWindowLong(handle, GWL_STYLE); //get the b style
style &= ~(WS_POPUP | WS_CAPTION); //reset the “caption” and “popup” bits
style |= WS_CHILD; //set the “child” bit
SetWindowLong(handle, GWL_STYLE, style); //set the new style of b

The
window->SetParent(control);
window->MoveWindow(rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top); //place b at (x,y,w,h) in a
control->UpdateWindow();

1 Like