[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 308
  • Last Modified:

Reusing forms as DLLs in non-Delphi applications

am trying to write a Delph-1-DLL with forms which should be opend by a
non-Delphi application as child windows of its client area.

So, I suppose, the

     constructor create(AOwner: TComponent) and the
     procedure CreateParams(var Params: TCreateParams)

of the derived class "TMyForm", have to perform the assignment of the non-Delphi
window to MyForm.Parent and MyForm.Owner. If "Hwnd" is the handle of the non-Delphi
window, the exported DLL procedure has the following form:

Procedure OpenMyForm (Hwnd: handle);
       .
      .
begin
      .
      .
  AOwner  := MakeOwnver (Hwnd);
  MyForm := TMyForm.Create (AOwner);
      .
      .
 
But how can I create a variable of type TComponent, if I only know the handle of this non-Delphi window, that means, how works "MakeOwnver".

If this concept isn't right, please, explain the correct method.

Thanks.
0
jt070397
Asked:
jt070397
  • 2
1 Solution
 
fsanchezCommented:
Try this:

  TMyForm = class(TForm)
  ...
  public
    constructor Create(H: HWnd);
  protected
    HandleParent: HWnd;

    procedure CreateParams(var Params: TCreateParams); override;
  end;


.......

constructor TMyForm.Create(H: HWnd);
begin
  HandleParent := H;
  inherited Create(nil);
end;

procedure TMyForm.CreateParams(var Params: TCreateParams);
begin
  (Self as TWinControl).CreateParams(Params);
  with Params do
  begin
    { You probably will need to play with different Flags here, for example, to hide the border: Style := Style and not WS_BORDER; }
    Style := Style or WS_CHILD;
    WndParent := HandleParent;
  end;
end;

0
 
fsanchezCommented:
Sorry, I have maken a mistake. Substitute the line
   
(Self as TWinControl).CreateParams(Params);

with this:

inherited CreateParams(Params);
0
 
jt070397Author Commented:
MyForm does not become a real child window of the Parent window HWnd.

Painting works correct, it is minimized if its parent is minimized, it receives the messages create, activate and deactivate, but it will not be distroyed if the parent window is
closed.

if borderstyle is none and
Params.Style := Params.Style
                or WS_CHILD OR WS_CLIPSIBLINGS
                or WS_CLIPCHILDREN
the position is at 0,0 of the desktop, even if the parent is moved.

if borderstyle is none and
Params.Style := WS_CHILD OR WS_CLIPSIBLINGS
                or WS_CLIPCHILDREN
the position is elsewhere within the parent window, but not at
defined (left,top).

Only if borderstyle is bsSizeable the position of MyForm is (left,top) relative to the parent.

Please, give more hints!

jt

0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now