delphi中DLL里的窗体显示到主界面上的Panel中

delphi中DLL里的窗体显示到主界面上的Panel中

DLL部分:

function LoadFromByDLL3(hParent: HWND): TForm;

begin  

  if not Assigned(fmFormDLL) then

     fmFormDLL:=TfmFormDLL.CreateParented(hParent); 


  Result:=fmFormDLL;

end;



Exe调用部分:

type

  TLoadFromByDLL3=function(hParent: HWND): TForm;


var

  Form2: TForm; 

  tmpHandle2: THandle; 


procedure TForm1.Button4Click(Sender: TObject);

begin

  if Assigned(Form2) then exit;


  Application.CreateForm(TForm,Form2);


  tmpHandle2:=LoadLibrary(PChar('LoadFormDLL.dll'));


    if tmpHandle2<>0 then begin

       @LoadFromByDLL3:=GetProcAddress(tmpHandle2,PChar('LoadFromByDLL3'));

       if @LoadFromByDLL3<>nil then begin

          //----------------------------------------------------

          Form2:=LoadFromByDLL3(Panel1.Handle);

          Form2.Align :=alClient;

          try  

          Form2.Show ;

          finally

          Form2:=nil;

          end;

          //----------------------------------------------------

          end;

       end; //end if 1

end;


相关推荐

[!--temp.pl--]