0
\$\begingroup\$

I use Urho3D which uses SDL2 as a window system. I want create another window as GUI and make it child for main window of Urho3D.

What I did is:

// insde virtual void Start() // Urho3D app
SDL_Window * sdlw = context->GetSubsystem<Graphics>()->GetWindow();
int width = context->GetSubsystem<Graphics>()->GetWidth();
int height = context->GetSubsystem<Graphics>()->GetHeight();
HWND mw = SDLWindows::GetWindowHWND(sdlw);
wpfC = WPFI::CreateWPFControl(0, 0, width, height);
HWND www = SetParent(wpfC, mw); // SetParent is windows function
if (www == NULL)
{
    std::cout << "------------------------------\n"
        << "www = NULL\n"
        << GetLastError() << "\n"
        << "------------------------------\n";
}

HWND SDLWindows::GetWindowHWND(SDL_Window * wnd)
{
    SDL_SysWMinfo sysInfo;
    SDL_VERSION(&sysInfo.version);
    SDL_GetWindowWMInfo(wnd, &sysInfo);
    return sysInfo.info.win.window;
}

I got Invalid window handle (1400) Error on SetParent().

I am not sure if I am doing it right, but I am sure that my wpfC is ok because I have another test project where it is working but instead SDL window I use win32 Window.

I think SDL_GetWindowWMInfo() give me a wrong handle.

Question is how to obtain HWND from SDL_Window correctly and be sure that it is right HWND?

If it is not possible do it that way, is there another way how to create child window from HWND inside main SDL2 window?

\$\endgroup\$
0
\$\begingroup\$

I found solution for Invalid window handle.

I edit source code of Urho3D engine and create function

void *GetSDLWindowHWND()
HWND hWnd = static_cast<HWND>(context->GetSubsystem<Graphics>()->GetSDLWindowHWND());

after that, SetParent() function working and my window child is displayed in Urho3D main window.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.