Page 1 of 1

Set parrent window by handle

Posted: Wed May 31, 2017 5:45 pm
by xpert13
Hello.

First of all I want to thank you for the project.

I have one question: can I set a parent window by handle (HWND) only? I need to render chromium browser in the window of another application.

I have work in such way in my current C++ project. CEF3 in C++ has method "SetAsChild":

Code: Select all

void attacheBrowserToWindow(HWND hWnd)
{
	// Create the single static handler class instance
	g_handler = new ClientHandler();
	g_handler->SetMainHwnd(hWnd);

	RECT rect;	  
	GetClientRect(hWnd, &rect);

	CefWindowInfo info;
	CefBrowserSettings settings;
	info.SetAsChild(hWnd, rect);

	// Creat the new child browser window
	CefBrowserHost::CreateBrowser(info, g_handler.get(), "about:blank", settings, NULL);
}

Do you have such method or maybe you will implement it in the future?

Re: Set parrent window by handle

Posted: Wed May 31, 2017 7:00 pm
by salvadordf
Hi,

I would have to create an overloaded version of TChromium.CreateBrowser with a handle and a rect to initialize the TCefWindowInfo record.

That's easy to do but I've never tried to use a handle from another application... in fact, I don't know if CEF3 is ready to handle that situation and I guess it would easily crash.

I''ll modify TChromium.CreateBrowser as soon as I can.

Re: Set parrent window by handle

Posted: Thu Jun 01, 2017 8:37 am
by salvadordf
Hi,

I uploaded a new version of CEF4Delphi with a new overloaded TChromium.CreateBrowser that takes a handle, the client rect and a window name to initialize the browser.

Re: Set parrent window by handle

Posted: Thu Jun 01, 2017 6:28 pm
by xpert13
Thank you. But after update it doesn't work att all. I have see a white screen only.

Delphi 2010. Please check it. I test it in the "SimpleBrowser" and "MiniBrowser" demos.

Re: Set parrent window by handle

Posted: Fri Jun 02, 2017 3:57 pm
by salvadordf
Hi,

I tested it again in Delphi Starter 10 and 10.2, and it works.

I'll have to ask some friends to test it in older Delphi versions because I only have a license of Delphi Starter 10 and 10.2

If you see a white background it means that the browser is fully initialized and it might be blocked by some firewall. Try running it outside Delphi with the firewall turned off.

Also consider downloading the latest Delphi Starter edition. It's FREE.
https://www.embarcadero.com/products/de ... l-download