Newsgroups : Borland : borland.public.delphi.nativeapi.win32 : 2006 Oct : App as a DLL, inside the form of another app
| Subject: | App as a DLL, inside the form of another app |
| Posted by: | "Z" (zingernospam@wot.com) |
| Date: | Thu, 26 Oct 2006 10:16:45 |
Hello,
Hope this is the right newsgroup. I'm trying to solve what seems like an
easy problem, but I'm stuck.
I have an application, which I'm trying to run as a DLL. This of course
means having a procedure like this in the main form of the DLL:
function CreateFrm(AHandle : THandle; ParentCtl : TWinControl): HWnd;
stdcall;
var
Frm: TDLLMainForm;
begin
Frm := TDLLMainForm.Create(Application);
Application.Handle := AHandle;
//Parent := ParentCtl; //(DANGER)
ShowModal;
Frm.BorderStyle := bsNone;
Frm.WindowState := wsMaximized;
Frm.Align := alClient;
Result := Frm.ParentWindow;
end;
CreateFrm is exported by the DLL. I call it from another application (which
has a panel on it, called SomePanel) as follows :
//declaration for import
function CreateFrm(AHandle : THandle; ParentCtl : TWinControl): HWnd;
stdcall; external 'TheDLL';
procedure TForm1.Button1Click(Sender: TObject);
begin
CreateFrm(Application.Handle,SomePanel);
end;
Here's the problem:
If I don't use the line above marked "Danger" (which I've commented out),
the DLL activates properly as a separate window and behaves OK.
However, if I include it, then the DLL activates itself inside "SomePanel"
(which is what I want), but does NOT behave ok, as everytime I try to do
something with it, one or another of its controls shows the message "Control
has no parent window" as an exception. As a result, while the application is
shown as I want, it won't do any of the things I want. :(
I've tried placing more stuff like "ParentWindow := ParentCtl.Parent" and so
on, but to no avail.
Please could you help? Thank you in advance for all your advice.
Z