如何在DLL中建立窗体?

miky 2004-12-21 01:03:02
不用VCL,那样dll好几百K.
...全文
239 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
thx1180 2004-12-25
  • 打赏
  • 举报
回复
看来我这块砖抛到水里去了:(
masterjames 2004-12-22
  • 打赏
  • 举报
回复
要小,可以在编译设置中做到,DLL也只有几十K
masterjames 2004-12-22
  • 打赏
  • 举报
回复
和EXE一样,只要接口函数中有SHOW就可以了
sunkevin 2004-12-22
  • 打赏
  • 举报
回复
up
thx1180 2004-12-22
  • 打赏
  • 举报
回复
我来抛块砖吧:)
DLL:
unit U_APIform;

interface

uses
Windows, Messages, SysUtils;

function ShowAPIModlessForm(AHandle: THandle): Longint; stdcall;

implementation

const
AppName = 'DllAPIform';

function DummyWindowProc (Wnd: hWnd; Msg, wParam: Word;
lParam: LongInt): LongInt; stdcall;
begin
Result := 0;
case Msg of
WM_DESTROY: PostQuitMessage(0);
else
Result := DefWindowProc(Wnd, Msg, wParam, lParam);
end;
end;

function ShowAPIModlessForm(AHandle: THandle): Longint;
var
cls: TWndClass;
Wnd: hWnd;
begin
Result := 0;
FillChar(cls, SizeOf(cls), 0);
cls.lpfnWndProc := @DummyWindowProc;
cls.hInstance := AHandle;
cls.lpszClassName := AppName;
RegisterClass(cls);

Wnd := CreateWindowEx(0, AppName, AppName,
WS_VISIBLE or //µ÷ÊÔʱÓÃ;
WS_SIZEBOX or WS_CAPTION or WS_POPUP,
363, 278, 305, 200, 0, 0, AHandle, nil);
if Wnd > 0 then
begin
UpdateWindow(Wnd);
ShowWindow(Wnd, SW_SHOW);
Result := Wnd;
end;
end;

end.

library DllAPIform;

uses
U_APIform in 'U_APIform.pas';

{$R *.res}

exports
ShowAPIModlessForm;

begin
end.

调用:
function ShowAPIModlessForm(AHandle: THandle): Longint;
stdcall; external 'DllAPIform.dll';

procedure TForm1.btnShowAPIModlessFormClick(Sender: TObject);
begin
if FAPIForm = 0 then
FAPIForm := ShowAPIModlessForm(Application.Handle);
end;

这样就可以把DLL中的无模式子窗体显示出来了:)
jinjazz 2004-12-21
  • 打赏
  • 举报
回复
带包编译啊
Blakhawk 2004-12-21
  • 打赏
  • 举报
回复
单片机开发吗?怎么对DLL大小要求这么严.
xx_adam 2004-12-21
  • 打赏
  • 举报
回复
差不多会这么大200K!我没有找到更好的处理办法!:(
miky 2004-12-21
  • 打赏
  • 举报
回复
to tomp()
你这个DLL怕有200K吧?再加点控件就过300了

我只是想知道怎么用SDK加上窗口,在窗口放一些控件,DLL和普通Exe不一样,有些工作要做,我想有经验的给点Tip, 我可以少走弯路.
ghchen 2004-12-21
  • 打赏
  • 举报
回复
学习
tomp 2004-12-21
  • 打赏
  • 举报
回复
调用dll的时候,在project的内容:
program Project1;

uses
Forms,
Unit2 in 'Unit2.pas' {Form1};

{$R *.res}

begin
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

在unit单元的内容:
unit Unit2;

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;

procedure test; far;external 'project2.dll';

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
test;
end;

end.


如果这个看不懂,我就没办法了
tomp 2004-12-21
  • 打赏
  • 举报
回复
在project单元的内容:
library Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1};

procedure test;
begin
Application.CreateForm(TForm1, Form1);
form1.show;
end;
{$R *.res}
exports test;
begin
end.

在unit单元的内容:
unit Unit1;

interface

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

type
TForm1 = class(TForm)
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

end.

这样编译后就是一个dll了。
IORILI 2004-12-21
  • 打赏
  • 举报
回复
up
yinzhiw 2004-12-21
  • 打赏
  • 举报
回复
学习
zdq801104 2004-12-21
  • 打赏
  • 举报
回复
学习学习!
miky 2004-12-21
  • 打赏
  • 举报
回复
单片机开发吗?怎么对DLL大小要求这么严.
我不想他太大而已,做成DLL就是为了小.


带包编译啊
这样还是大(加上包),不过DLL多了就不觉得了,但其他语言能调用吗?
纯冰糖 2004-12-21
  • 打赏
  • 举报
回复
SDK比较麻烦的...
jinjazz 2004-12-21
  • 打赏
  • 举报
回复
只包含一个form的话,dll带包编译只有11k左右,如果是10个dll加上bpl也只有几百k,dll和bpl文件都可以加壳压缩
kuki84 2004-12-21
  • 打赏
  • 举报
回复
那用sdk,一样做啊
jinjazz 2004-12-21
  • 打赏
  • 举报
回复
project-option-package-build with packages..

然后发布的时候把bpl和所有dll放到同一目录下

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧