关于消息的问题!高手帮忙!

bluesage 2002-11-30 03:24:43
一个BUTTON1按下后,向另一个BUTTON2发送了一条自定义消息,BUTTON2的接受消息的过程怎么写?下面代码中我想让BUTTON2响应,我觉得应该是可以。
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
MYMESSAGE = WM_USER+200 ;
type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure getmess(var msg : TMessage); message MYMESSAGE ;
procedure Button1Click(Sender: TObject);

private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}
procedure tform1.getmess(var msg : TMessage) ;
begin
showmessage('i have got it');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
postmessage(form1.Handle ,MYMESSAGE,0,0);
end;

end.

...全文
46 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluesage 2002-11-30
  • 打赏
  • 举报
回复
我在测试DLL的时候,我改变了DLL中函数的参数,可是怎么更新测试程序啊??
xzgyb 2002-11-30
  • 打赏
  • 举报
回复
unit Unit1;

interface

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

const
MYMESSAGE = WM_USER+200 ;

type
TMainForm = class(TForm)
Button1: TButton;
Button2: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
FOldWndProc: TWndMethod;

procedure NewWndProc(var Msg: TMessage);
public
{ Public declarations }
end;

var
MainForm: TMainForm;

implementation

{$R *.dfm}

procedure TMainForm.FormCreate(Sender: TObject);
begin
FOldWndProc := Button2.WindowProc;
Button2.WindowProc := NewWndProc;
end;

procedure TMainForm.NewWndProc(var Msg: TMessage);
begin
if Msg.Msg = MYMESSAGE then
ShowMessage('I have got it')
else
FOldWndProc(Msg);
end;

procedure TMainForm.Button1Click(Sender: TObject);
begin
SendMessage(Button2.Handle, MYMESSAGE, 0, 0);
end;

end.

不过没什么必要

5,388

社区成员

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

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