如何在DLL中编一个过程,以实现对外部某一个窗体中的标签控件的标题进行修改?

sangdy 2003-08-23 01:15:13
如何在DLL中编一个过程,以实现对外部某一个窗体中的标签控件的标题进行修改?
另外在很多材料上都说要在DLL中的过程或函数后面加一个stdcall,但我在加了之后,DLL中的函数或过程调用却出错,不加反倒正常。
我用的是DELPHI7,WIN98SE
...全文
42 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
lxpbuaa 2003-08-23
  • 打赏
  • 举报
回复
看如下的例子,你最后将过程ChangeLabel移动到dll即可:

unit Unit1;

interface

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

const WM_ChangeLabel = WM_USER + 1024; //自定义消息

type
TForm1 = class(TForm)
Button2: TButton;
Label1: TLabel;
procedure Button2Click(Sender: TObject);
private
procedure WMChangeLabel(var Message: TMessage);
message WM_ChangeLabel;
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure ChangeLabel(Handle: THandle; Name, NewText: PChar); //Handle接受需要被修改的标签所在窗体的句柄,Name接受标签控件的名字,NewText为新的标签
begin
SendMessage(Handle, WM_ChangeLabel, Integer(Name), Integer(NewText)); //WM_ChangeLabel为自定义消息,如:
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
ChangeLabel(Handle, 'Label1', 'lxphasid');
end;

procedure TForm1.WMChangeLabel(var Message: TMessage);
var
tfLabel: TLabel;
begin
with Message do
if Msg = WM_ChangeLabel then
begin
tfLabel := TLabel(FindComponent(PChar(WParam)));
if tfLabel <> nil then
tfLabel.Caption := PChar(LParam);
end;
end;

end.

—————————————————————————————————
宠辱不惊,看庭前花开花落,去留无意;毁誉由人,望天上云卷云舒,聚散任风。
—————————————————————————————————

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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