View the Form of a DLL in Delphi DX10

1

I have the following situation: I have a project, which calls a DLL and it has a form. Until that moment 'OK', it performs the call and displays the form, only one thing that bothers me visually is that the system tray has two open applications, one from the project and the other from the DLL.

Opening the form in ShowModal , and pressing ctrl + tab for the project, it gives focus but I can not access anything.

My question is how to leave only one application in the system tray.

DLL encoding

library ChamadaForm;

uses
  SysUtils,
  Forms,
  Classes;

{$R *.res}

procedure exibir; stdcall;
var
 frm : TForm;
begin
  frm := TForm.Create(nil);
  frm.ShowModal;
  freeAndNil(frm);
end;

exports
  exibir;
begin
end.

Calling the DLL in the Project.

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;


implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
 exibir : procedure; stdcall;
 handle: THandle;
begin
  handle := LoadLibrary('ChamadaForm.dll');
  if Handle <> 0 then
  begin
    @exibir := GetProcAddress (Handle, 'exibir');
    if @exibir <> nil then
      exibir;
    FreeLibrary (Handle);
  end;
end;

end.
    
asked by anonymous 29.09.2016 / 12:52

1 answer

2

Regardless of whether you run a ShowModal you should remember that we are running a second application!

There are other ways to Hookar the application inside the other!

But Delphi for this case can be quite simple. Access the project's Source (from the DLL in the case) and add this line before the Application.Run .

Application.MainFormOnTaskBar := False;

Note that the command name itself is very intuitive!

    
29.09.2016 / 13:16