Home > Software design >  Is it possible to combine GLFW window with WINAPI controls?
Is it possible to combine GLFW window with WINAPI controls?

Time:12-08

I have such 3D scene in a window which was created using GLFW: glfw occt

Now I'd like to have some buttons and lists and input fields in here too. WinAPI provides those. How do I achieve this and add controls to my window?

I checked the Internet, and I don't see much questions about using WinAPI controls with GLFW window. As far as I remember, GLFW does not appreciate when someone tries to snatch HWND of its window (I think, it's protected, since they strive for cross-platform implementation of their library). I have seen a question when someone tried to embed a GLFW window into another window, which does not fit my idea. I completely appreciate if GLFW handles an input on scene - mouse clicks on scene, drags, key presses and other events, but controls, of course, should be reachable as well. Alternatively I may go with Dear ImGui, and use those controls in my window, if adding WinAPI controls to GLFW window appears too complicated.

CodePudding user response:

You have to do a better research. Instead of checking the Internet, why didn't you just visited the most relevant sites: WinAPI and GLFW

As far as I remember, GLFW provides a Native access.

For example, to create a button, you'll need the HWND of the parent window (see here):

HWND glfwGetWin32Window(GLFWwindow *window);

and then (see here)

HWND hwndButton = CreateWindow( 
    L"BUTTON",  // Predefined class; Unicode assumed 
    L"OK",      // Button text 
    WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles 
    10,         // x position 
    10,         // y position 
    100,        // Button width
    100,        // Button height
    m_hwnd,     // Parent window
    NULL,       // No menu.
    (HINSTANCE)GetWindowLongPtr(m_hwnd, GWLP_HINSTANCE), 
    NULL);      // Pointer not needed.

After you've created the button, listen to the incoming events and act properly.

  • Related