New window as child (how to?)

It is possible create window and add it as child in main urho3d window?

From documentation Urho have SDL as windowing system if I am right, therefore I need use SDL directly or it is possible do it with Urho?

I did something but it is not working (windows is not visible or shown)

// inside virtual void Start()
		SDL_Window * sdlw = context_->GetSubsystem<Graphics>()->GetWindow();
		wpfC = WPFI::CreateWPFControl(0, 0, 600, 300);
		SDLWindows::CreateSecondWindow(wpfC, sdlw);
// -----------------------------------------------------------------------

void SDLWindows::CreateSecondWindow(HWND hwnd, SDL_Window * sw)
	Uint32 flags = SDL_WINDOW_SHOWN

	sw = SDL_CreateWindowFrom(hwnd, flags); // with flags or without, not difference
	if (sw == nullptr)
		std::cout << "-------------------\n" << "sdlWnd = NULL\n" << "-------------------\n";
		std::cout << "-------------------\n" << "sdlWnd = ok\n" << "-------------------\n";

	SDL_SetWindowTitle(sw, "SDL Window - Set by SDL"); 
	SDL_Surface* s = SDL_GetWindowSurface(sw);
	SDL_FillRect(s, &s->clip_rect, 0xffff00ff);

Since you use HWND your app won’t be cross platform. If you don’t want cross platform support then you could use winapi directly and GetExternalWindow to obtain the main window’s hwnd and use it as a parent. Theoretically…

1 Like

Thanks for reply.
But ExternalWindow is NULL by default (from documentation). You mean obtain main window from Urho3D ?
If possible I want use Urho3D window as main window.
Btw. I am not looking for crossplatform solution.

I have trouble get right HWND from window

SDL_Window * sdlw = context->GetSubsystem<Graphics>()->GetWindow();
HWND mw = SDLWindows::GetWindowHWND(sdlw);

// ...

HWND SDLWindows::GetWindowHWND(SDL_Window * wnd)
	SDL_SysWMinfo sysInfo;

	SDL_GetWindowWMInfo(wnd, &sysInfo);

// ...

HWND www = SetParent(wpfC, mw);
if (www == NULL)
		std::cout << "------------------------------\n"
			<< "www = NULL\n"
			<< GetLastError() << "\n"
			<< "------------------------------\n";

I got Invalid window handle (1400). Error
I am sure that SDL window is problematic because my wpfC HWND is working on my previous test project, but instead SDL window I use win32 window.

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.

But one problem with that, when I set parent for my window, background is not transparent. It make “hole” in to Urho renderer. On my test project without Urho, it is working as expected.

Could you share a screenshot displaying this issue? I’m not sure what you mean by it “making a hole”.

making hole means, window is transparent, but what is displayed behind transparent is not Urho3D but some default win32 background color.

  1. First image is how it should look like. (window is displayed as not child)

  2. Second image is how it is like if window is child with SetParent and use ElementHost for make background transparent. (if is not transparent, background is black)

Hey Elendil!
Note it only works for certain platforms, such as Windows and OSX.

On Linux is does work using Qt:

@Elendil Are you sure you need a second SDL window, btw?
In the screenshots the second window does not leave the main window.

I need only Windows. Does the SetWindowOpacity make whole windows transparent or only certain area (which have transparent background)? Because this is big difference and I need window with background transparent (as you see on images I post above) where objects (text and button) are not transparent.

This is the right question, if you know how to embed WPF renderer in to Urho renderer, I don’t need second window. (I know that WPF can do D3DImage but I am not sure if it is right way to go with performance).
And yes, I need the second window not leave main window and resize as main window resize.

I need use WPF as GUI. Therefore I need second window which will be front of Urho3D renderer and tied to the main window as described. If it will be SDL_Window or WPF or Win32, I don’t care. I tried use WPF as ExternalWindow for Urho, problem with that is Renderer is front of WPF content. I am going to try another few ideas.

What reasons do you have to not use Urho’s UI subsystem in this case?

I am much confortable with WPF. Another + is once it will be working, I can easyly use it in another game engine.