Attach A GLFWwindow To Windows Window Client Area?

Hi Folks:

Developing on Windows 10 Pro, Visual Studio 2017, C++.

I posted this a couple of weeks ago.

The first window my application opens has a row of menu drop down across the top.

All of the application’s real business is done through dialogs that are accessed through the menu items.

I want this opening screen to serve as a splash screen, with some attractive animated 3D graphics. This will be in the background as the user works with the dialogs displayed in front of it.

So I’d like an GLFWwindow to be attached to the client area of the first screen. As the application’s first screen is moved or resized the GLFWwindow should seamlessly move and resize with it.

I’m sure there’s a site describing exactly what I need to do, but I thought I’d give it a shot.

I’m sizing and positioning a GLFWwindow over the main window’s client rectangle by servicing the main window dialog’s WM_SIZE, WM_MOVE and WM_WINDOWPOSCHANGED.

I had to use the GLFW_FLOATING hint in order to display the splash screen over the main window. .

The problem now is that the GLFWwindow is top most, and the dialogs that pop from the menus are displayed behind it.

Is there a way to have the GLFWwindow display in front of a particular Windows window?

Or better yet, can I throw this first experiment away and go to a site that shows me what to do?

  Thanks
  Larry

GLFW has an open issue on creating an OpenGL context in an existing window.

Trying to achieve this with an extra window is going to be very difficult to get right as you’re finding. The alternatives are to use a UI system such as Qt which has an OpenGL widget you can use, or use an OpenGL UI library for your main menu such as in this post on UI in GLFW.

Thanks dougbinks:

I found this page that describes using PIXELFORMATDESCRIPTOR to create an OpenGL context in a Windows window.

I’d like to work with a GLFWwindow after I get this set up, but I don’t know how to do that, fi it can be done.

The tutorial I’ve been using to learn OpenGL uses glfwCreateWindow() to create the window and then calls glfwMakeContextCurrent(window) to create the context. Now that I’m becoming familiar with GLFW I’d rather not change to another OpenGL interface. I’ve already built some nice tools that rely on GLFW.

Is there some way to use GLFW after I create the context with PIXELFORMATDESCRIPTOR and wglMakeCurrent?

Thanks
Larry

@larryl Why do you want to create the context manually if you’re going to attach the window to GLFW?

Thanks Everybody:

I think I get it.

I’m using Windows to run the user interface, so I won’t be using GLFW.

Sorry that took so long for me to figure out.

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