Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Set parrent window by handle

Post Reply
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Set parrent window by handle

Post 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?
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Set parrent window by handle

Post 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.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Set parrent window by handle

Post 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.
User avatar
xpert13
Posts: 39
Joined: Wed May 31, 2017 5:26 pm

Re: Set parrent window by handle

Post 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.
User avatar
salvadordf
Posts: 4564
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Set parrent window by handle

Post 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
Post Reply