title: How display a background image and center a panel in a dll Form?
body: <p>I want load a image that will be the background of a maximized Form that stays in a dll.</p>
  
  <p>The dll is called from a Vcl Form Application but have a trouble where not is possible load the background image on Form, the dll always crashes.</p>
  
  <p>Thank you by you help.</p>
  
  <p>===========================================================================</p>
  
  <p><strong><em>Executable</em></strong></p>
  
  <pre><code>unit Unit2;
  interface
  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls;
  
  type
    TForm2 = class(TForm)
      btn1: TButton;
      procedure btn1Click(Sender: TObject);
    end;
  
  var
    Form2: TForm2;
  
  implementation  {$R *.dfm}
  
  procedure LoadDLL;
  type
    TShowformPtr = procedure; stdcall;
  var
    HDLL: THandle;
    Recv: TShowformPtr;
  begin
    HDLL := LoadLibrary('lib.dll');
    if HDLL &lt;&gt; 0 then
    begin
      @Recv := GetProcAddress(HDLL, 'Recv');
      if @Recv &lt;&gt; nil then
      Recv;
    end;
    //FreeLibrary(HDLL);
  end;
  
  procedure TForm2.btn1Click(Sender: TObject);
  begin
  LoadDLL;
  end;
  
  end.
  </code></pre>
  
  <p><strong>Dll</strong></p>
  
  <p>Main:</p>
  
  <pre><code>library Project2;
  uses
    SysUtils, Classes, Unit1, Unit2;
  
  {$R *.res}
  
  procedure Recv; stdcall;
  begin
    showform;
  end;
  
  exports
    Recv;
  
  begin
  end.
  </code></pre>
  
  <p>Unit1 (Form):</p>
  
  <pre><code>unit Unit1;
  
  interface
  
  uses
    Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
    System.Classes, Vcl.Graphics,
    Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.ExtCtrls;
  
  type
    TForm1 = class(TForm)
      img1: TImage;
      pnl1: TPanel;
      procedure FormShow(Sender: TObject);
    private
      { Private declarations }
      procedure CreateParams(var Params: TCreateParams); override;
    public
      { Public declarations }
    end;
  
  var
    Form1: TForm1;
  
  implementation
  
  {$R *.dfm}
  
  procedure TForm1.CreateParams(var Params: TCreateParams);
  begin
    inherited CreateParams(Params);
     Params.WndParent:= Application.Handle;
    Params.ExStyle := Params.ExStyle or WS_EX_TOPMOST or WS_EX_TRANSPARENT;
    Params.ExStyle := WS_EX_TRANSPARENT or WS_EX_TOPMOST;
  end;
  
  procedure TForm1.FormShow(Sender: TObject);
  begin
    brush.Style := bsclear;
    img1.Picture.LoadFromFile(IncludeTrailingBackslash(GetCurrentDir) + 'background.bmp');
    SetWindowPos(Form1.handle, HWND_TOPMOST, Form1.Left, Form1.Top, Form1.Width,
      Form1.Height, 0);
  
    ShowWindow(Application.handle, SW_HIDE);
  
    pnl1.Top := (self.Height div 2) - (pnl1.Height div 2);
    pnl1.Left := (self.Width div 2) - (pnl1.Width div 2);
  end;
  
  end.
  </code></pre>
  
  <p>Unit2:</p>
  
  <pre><code>unit Unit2;
  
  interface
  
  Uses
    windows,
    Unit1,
    SysUtils;
  
    procedure showform;
  
  implementation
  
  procedure showform;
  begin
    Form1 := TForm1.Create(Form1);
    sleep(100);
    Form1.Show;
    Form1.Pnl1.Visible := True;
  end;
  
  end.
  </code></pre>