Hi,
I would like some help, I need to work with a DLL like DLLBrowser demo, but in my case I need to set the host application mainform or any other form in exe as parent of then Chromium control in the DLL. But all was i tried diden't work.
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.
Cef4Delphi DDL with host application forms as parent
-
- Posts: 3
- Joined: Thu Feb 22, 2024 7:13 pm
- salvadordf
- Posts: 4304
- Joined: Thu Feb 02, 2017 12:24 pm
- Location: Spain
- Contact:
Re: Cef4Delphi DDL with host application forms as parent
Hi,
I've never tried that but I would start by something simpler like creating a panel using a DLL function and set the owner and the parent to the main application form.
I don't know if that's even possible but some people suggest using packages instead :
https://stackoverflow.com/questions/10347921/delphi-can-you-have-a-component-class-definition-in-a-dll-and-load-and-create-i
CEF4Delphi browsers require access to GlobalCEFApp and that can be a problem when the browser was created using a DLL function :
http://www.delphigroups.info/2/1e/412626.html
I've never tried that but I would start by something simpler like creating a panel using a DLL function and set the owner and the parent to the main application form.
I don't know if that's even possible but some people suggest using packages instead :
https://stackoverflow.com/questions/10347921/delphi-can-you-have-a-component-class-definition-in-a-dll-and-load-and-create-i
CEF4Delphi browsers require access to GlobalCEFApp and that can be a problem when the browser was created using a DLL function :
http://www.delphigroups.info/2/1e/412626.html
-
- Posts: 3
- Joined: Thu Feb 22, 2024 7:13 pm
Re: Cef4Delphi DDL with host application forms as parent
Hi,
Thanks. Yesterday I go on trying, and I got a way to make it work for my purpose. I need to test it a little more, and probably do some manual controls.
Bellow follow the main sourcecode sample if someone needs it too.
procedure loadURL(exeFormHandle: THandle); // Method of a unit in the DLL
var
xDllForm: TForm4;// A Form with a TChromiumWindow component
begin
xDllForm := TForm4.Create(nil);
// Winapi.Windows.SetPArent
SetParent(xDllForm.Handle, exeFormHandle);// Setting a form in the exe as parent of the form in the DLL
xDllForm.Show;
end;
Thanks. Yesterday I go on trying, and I got a way to make it work for my purpose. I need to test it a little more, and probably do some manual controls.
Bellow follow the main sourcecode sample if someone needs it too.
procedure loadURL(exeFormHandle: THandle); // Method of a unit in the DLL
var
xDllForm: TForm4;// A Form with a TChromiumWindow component
begin
xDllForm := TForm4.Create(nil);
// Winapi.Windows.SetPArent
SetParent(xDllForm.Handle, exeFormHandle);// Setting a form in the exe as parent of the form in the DLL
xDllForm.Show;
end;
Last edited by carlos.ricardo on Fri Feb 23, 2024 1:35 pm, edited 1 time in total.
Re: Cef4Delphi DDL with host application forms as parent
Here is an example of how this can be done:carlos.ricardo wrote: ↑Thu Feb 22, 2024 7:21 pm Hi,
I would like some help, I need to work with a DLL like DLLBrowser demo, but in my case I need to set the host application mainform or any other form in exe as parent of then Chromium control in the DLL. But all was i tried diden't work.
Code: Select all
library DLLBrowser;
{$I cef.inc}
uses
SysUtils,
System.Types,
Winapi.Windows,
uCEFApplication,
uCEFChromium,
uCEFWindowParent;
{$R *.res}
var
CEFWindowParent1: TCEFWindowParent;
Chromium1: TChromium;
procedure InitializeCEF4Delphi; stdcall;
begin
GlobalCEFApp := TCefApplication.Create;
GlobalCEFApp.SetCurrentDir := True;
GlobalCEFApp.BrowserSubprocessPath := 'SubProcess.exe';
GlobalCEFApp.StartMainProcess;
end;
procedure FinalizeCEF4Delphi; stdcall;
begin
DestroyGlobalCEFApp;
end;
procedure ShowBrowser(FormHandle: HWND; FormHeight, FormWidth: Integer); stdcall;
begin
if CEFWindowParent1 = nil then
begin
CEFWindowParent1 := TCEFWindowParent.Create(nil);
CEFWindowParent1.ParentWindow := FormHandle;
CEFWindowParent1.BoundsRect := Rect(0, 0, FormWidth, FormHeight);
end;
Chromium1 := TChromium.Create(nil);
Chromium1.DefaultURL := 'https://www.google.com/';
Chromium1.CreateBrowser(CEFWindowParent1);
end;
exports
InitializeCEF4Delphi,
FinalizeCEF4Delphi,
ShowBrowser;
begin
end.