如何接受SendMessage发送的自定义附加消息?

littlebird82 2003-11-26 03:30:05
在一个公共模块中定义了
TFormInfo = record
FFormClass : TFormClass;
Ffm : TComponent;
FFormCaption : String;
end;

在FORM2中发送消息
var
fi: TFormInfo;
begin
fi.FFormClass := TForm3;
fi.Ffm := form3;
fi.FFormCaption := 'Form3';
sendmessage(form1.handle, wm_user+1, 0, lparam(fi));
end;

在Form1中如何接收FORM2发送过来的自定义附加消息?
...全文
212 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
sundayboysII 2003-11-28
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, ExtCtrls, StdCtrls;
const
WM_USERMY = WM_USER + 122;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WM_USERMY(var msg:TMessage);message WM_USERMY;
end;
TMyRecord = record
I: Integer;
S: string;
end;
PMyRecord = ^TMyRecord;
var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
MyRecord: TMyRecord;
begin
MyRecord.I := 1;
MyRecord.S := 'Test';
SendMessage(Handle, WM_USER + 122, 0, lparam(@MyRecord));
end;

procedure TForm1.WM_USERMY(var msg: TMessage);
var

PP: PMyRecord;
begin
PP := Pointer(Msg.LParam);
ShowMessage(pP.S);
end;

end.
littlebird82 2003-11-28
  • 打赏
  • 举报
回复
能否给出详细的接收代码?
rick29 2003-11-28
  • 打赏
  • 举报
回复
interface中:
procedure RCV (……); message WM_MYMESS;
省略号是你的消息参数及其类型,比如类似于Delphi的TMessage、TWMDrawItem等。

在implementation中加入其实现,参考一下VCL中的那些消息实现吧。



lingee1999 2003-11-28
  • 打赏
  • 举报
回复
Message.lParam
littlebird82 2003-11-28
  • 打赏
  • 举报
回复
各位大哥帮帮忙,小弟我正急着用的。
littlebird82 2003-11-27
  • 打赏
  • 举报
回复
请写出接收的代码?
aiirii 2003-11-26
  • 打赏
  • 举报
回复
sendmessage(form1.handle, wm_user+1, 0, lparam(@fi));

然後, 在fomr2定義一個指針, 對應接收就可!!

1,183

社区成员

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

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