現狀是這樣的,我寫了一個帶Form的Dll,form里面有2個按鈕Button1和button2, 主表單中有個Panel,點擊Panel呼叫Dll介面把Dll中的Form顯示到主狀體的panel中,這個實作起來是比較簡單的,現在的問題是,當我點擊button1的時候,我想讓主表單最大化,點button2的是要讓主表單最小化,其實主要是為了要讓Dll主動與主表單通信,這個要怎樣實作呢?以前對Dll的接觸不是很多,所以在此請各位大牛些賜教了。
uj5u.com熱心網友回復:
等待大牛賜教,在此感謝了uj5u.com熱心網友回復:
我所知道的:回呼函式、發送訊息。可以看看這個:
http://bbs.csdn.net/topics/390795469
uj5u.com熱心網友回復:
呼叫DLL的時候,把主表單句柄傳給DLL,DLL里點擊按鈕的時候發訊息給主表單,
主表單根據訊息最大化。。。
uj5u.com熱心網友回復:
Dll form通過訊息來控制主表單可用實作了。但是新問題出來了。我發現dll中的form被呼叫后。form中控制元件的咋就成了靜態的了。比如說我用XE6寫了個dll,Dll里面有個form,form放了個TFlowPanel控制元件。這個控制元件有自動布局在它里面的控制元件位置功能,但是一旦主表單呼叫顯示了Dll中的form后,TFlowPanel控制元件就沒有自動布局它里面控制元件的位置作用了,不知道為什么會這樣uj5u.com熱心網友回復:
給主表單post一個訊息就可以啊uj5u.com熱心網友回復:
DLL表單
library dllform;
{ Important note about DLL memory management: ShareMem must be the
first unit in your library's USES clause AND your project's (select
Project-View Source) USES clause if your DLL exports any procedures or
functions that pass strings as parameters or function results. This
applies to all strings passed to and from your DLL--even those that
are nested in records and classes. ShareMem is the interface unit to
the BORLNDMM.DLL shared memory manager, which must be deployed along
with your DLL. To avoid using BORLNDMM.DLL, pass string information
using PChar or ShortString parameters. }
uses
SysUtils,Forms,
Classes,
UnitdllInterface in 'UnitdllInterface.pas',
Unit3 in 'Unit3.pas' {Form3};
{$R *.res}
procedure ShowDLLForm(Parent:THandle;aInteractionData:TInteractionData); stdcall;
begin
Application.Handle:=Parent;
Form3:=TForm3.Create(Application);
Form3.InteractionData:=aInteractionData;
Form3.Show;
Form3.BringToFront;
end;
exports
ShowDLLForm;
begin
end.
DLL里面的表單
unit Unit3;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,UnitdllInterface, StdCtrls;
type
TForm3 = class(TForm)
btn1: TButton;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
private
fInteractionData: TInteractionData;
{ Private declarations }
public
property InteractionData: TInteractionData read fInteractionData write fInteractionData;
end;
var
Form3: TForm3;
implementation
{$R *.dfm}
procedure TForm3.btn1Click(Sender: TObject);
begin
fInteractionData.DoAddData(VarArrayOf(['MAX'])); //ê1?÷3ìDò×?′ó?ˉ
end;
procedure TForm3.btn2Click(Sender: TObject);
begin
fInteractionData.DoAddData(VarArrayOf(['MIN'])); //ê1?÷3ìDò×?′ó?ˉ
end;
procedure TForm3.FormCreate(Sender: TObject);
begin
fInteractionData:=TInteractionData.Create;
end;
procedure TForm3.FormDestroy(Sender: TObject);
begin
fInteractionData.Free;
end;
procedure TForm3.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Action := caFree;
end;
end.
//最重要的一個互動使用的
unit UnitdllInterface;
interface
uses
Classes, Menus, Variants, Graphics, Controls, Forms, Dialogs, StdCtrls;
type
TOnAddData = procedure(Sender: TObject; Value: Variant) of object;
TInteractionData = class
private
fOnAddData: TOnAddData;
ftestpara: string;
public
procedure DoAddData(Value: Variant);
property OnAddData: TOnAddData read fOnAddData write fOnAddData;
property testpara:string read ftestpara write ftestpara;
end;
implementation
{ TSetData }
procedure TInteractionData.DoAddData(Value: Variant);
begin
if Assigned(fOnAddData) then fOnAddData(self,Value);
end;
end.
//最后一個呼叫dll的主程式
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls,UnitdllInterface;
type
TForm1 = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
fInteractionData: TInteractionData;
procedure AddData(Sender: TObject; Value: Variant); //接收dll發送來的資料
public
property InteractionData: TInteractionData read fInteractionData write fInteractionData;
end;
var
Form1: TForm1;
procedure ShowDLLForm(Parent:THandle;aInteractionData:TInteractionData); stdcall; external 'dllform.dll';
implementation
{$R *.dfm}
procedure TForm1.AddData(Sender: TObject; Value: Variant);
begin
if Value[0]='MAX' then
begin
Self.WindowState:=wsMaximized;
end;
if Value[0]='MIN' then
begin
Self.WindowState:=wsMinimized;
end;
end;
procedure TForm1.btn1Click(Sender: TObject);
begin
ShowDLLForm(Application.Handle,fInteractionData);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
fInteractionData:=TInteractionData.Create;
fInteractionData.OnAddData:=AddData;
end;
end.
//效果圖
uj5u.com熱心網友回復:
原始碼已上傳,僅供學習使用http://download.csdn.net/detail/gykthh/7744787
uj5u.com熱心網友回復:
請教一下,樓主這個皮膚控制元件用的是什么?uj5u.com熱心網友回復:
我是在win8下面寫的 打開程式 自己就變成這樣的了 沒用皮膚uj5u.com熱心網友回復:
請問你是用什么方法將DLL中的表單加載到主表單的Panel上的?
可能是加載方法有問題導致Panel上表單失效。
uj5u.com熱心網友回復:
基本上就這2個方法比較簡單易行
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/101735.html
標籤:VCL組件開發及應用
