Delphi 调用dll中的窗体
2015-08-26 13:48
393 查看
1.定义窗体
unit UDllForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDllForm = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DllForm: TDllForm;
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
procedure ShowDllForm;stdcall;
implementation
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
begin
Application.handle:=parent;
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.ParentWindow:=Parent;//将容器设置为父窗口
DllForm.Show;
end;
procedure ShowDllForm;stdcall;
begin
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.Show;
end;
{$R *.dfm}
procedure TDllForm.btn1Click(Sender: TObject);
begin
ShowMessage('HELLO');
end;
end.
2.定义dll
library Formindll;
uses
SysUtils,
Classes,
UDllForm in 'UDllForm.pas' {DllForm};
{$R *.res}
exports
ShowDllFormInPanel,
ShowDllForm;
begin
end.3.dll窗体调用
注意:dll窗体不能直接放在父窗体里面 ,这里可以使用panel作为父窗体 对应过程ShowDllFormInPanel
dll窗体不放在父窗体 则直接使用ShowDllForm 过程,想一个对话框的形式
unit Unit1;
interface
uses
SysUtils,Classes,Forms,Windows,Messages, Controls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
pnl1: TPanel;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ShowDllFormInPanel(Parent:THandle);stdcall; external 'E:\test7\formindll.dll';
procedure ShowDllForm; stdcall; external 'E:\test7\formindll.dll';
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
ShowDllFormInPanel(pnl1.Handle);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
ShowDllForm;
end;
end.
unit UDllForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TDllForm = class(TForm)
btn1: TButton;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
DllForm: TDllForm;
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
procedure ShowDllForm;stdcall;
implementation
procedure ShowDllFormInPanel(Parent:THandle);stdcall;
begin
Application.handle:=parent;
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.ParentWindow:=Parent;//将容器设置为父窗口
DllForm.Show;
end;
procedure ShowDllForm;stdcall;
begin
if DllForm = nil then
DllForm:= TDllForm.Create(Application);
DllForm.Show;
end;
{$R *.dfm}
procedure TDllForm.btn1Click(Sender: TObject);
begin
ShowMessage('HELLO');
end;
end.
2.定义dll
library Formindll;
uses
SysUtils,
Classes,
UDllForm in 'UDllForm.pas' {DllForm};
{$R *.res}
exports
ShowDllFormInPanel,
ShowDllForm;
begin
end.3.dll窗体调用
注意:dll窗体不能直接放在父窗体里面 ,这里可以使用panel作为父窗体 对应过程ShowDllFormInPanel
dll窗体不放在父窗体 则直接使用ShowDllForm 过程,想一个对话框的形式
unit Unit1;
interface
uses
SysUtils,Classes,Forms,Windows,Messages, Controls, StdCtrls, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
pnl1: TPanel;
btn2: TButton;
procedure btn1Click(Sender: TObject);
procedure btn2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
procedure ShowDllFormInPanel(Parent:THandle);stdcall; external 'E:\test7\formindll.dll';
procedure ShowDllForm; stdcall; external 'E:\test7\formindll.dll';
implementation
{$R *.dfm}
procedure TForm1.btn1Click(Sender: TObject);
begin
ShowDllFormInPanel(pnl1.Handle);
end;
procedure TForm1.btn2Click(Sender: TObject);
begin
ShowDllForm;
end;
end.
相关文章推荐
- DELPHI XE5安装
- Delphi SendMessage PostMessage 原理和区别
- Delphi dll定义与调用
- EPASWMM界面部分编译
- github上的一些Delphi开源项目
- delphi创建具有托盘的服务程序(service)
- Delphi ADOQuery连接数据库的查询、插入、删除、修改
- Delphi 修改注册表使程序开机启动
- Delphi6 调试
- Delphi6 IDE 一些配置说明
- delphi md5算法
- Delphi控件的透明与不透明(要挨个解释一下原因),对InvalidateControl的关键理解
- 百度输入提示 Delphi 实现
- Delphi中对BCD码的直接支持 (转)
- Delphi源码分析之System.DateUtils Start/End functions
- Delphi7 第三方控件1stClass4000的TfcImageBtn按钮控件动态加载jpg图片例子
- Delphi中常用的各个关键字名称及用法
- DelPhi 动态给ComBoBox赋值,从ComBoBox中取值
- Delphi2010中DataSnap技术网摘
- 关于win7 下delphi7出现重新注册,无法打开的故障解决办法