为什么收不到自己发送的消息?

luxiaoban 2001-09-17 09:21:02
我有正在编写一个控件,

有一个消息需要发送给自己,

但好象自己收不到这个消息,为什么?

BTW:这个控件是继承于TComponent.
...全文
230 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
largewang(垃圾王):

谢谢,成功了
largewang 2001-09-17
  • 打赏
  • 举报
回复
unit Unit1;

interface

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

const wm_me = WM_USER + 1000;

type
TMyComponent = class(TComponent)
private
procedure ReceiveMessage(var Msg: TMessage); message wm_me;
public
function Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
end;


TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private

{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

{ TMyComponent }

procedure TMyComponent.ReceiveMessage(var Msg: TMessage);
begin
showmessage('afd');
end;

function TMyComponent.Perform(Msg: Cardinal; WParam, LParam: Longint): Longint;
var
Message: TMessage;
begin
Message.Msg := wm_me;//Msg;
Message.WParam := WParam;
Message.LParam := LParam;
Message.Result := 0;
if Self <> nil then Dispatch(Message);
Result := Message.Result;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
M: tmycomponent;
begin
M:= tmycomponent.Create(Self);
try
m.Perform(wm_me,0,0);
finally
m.Free;
end;

end;

end.
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
please answer me.
largewang 2001-09-17
  • 打赏
  • 举报
回复
Let me try.
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
I want to know why can not receive message.
gzh5200 2001-09-17
  • 打赏
  • 举报
回复
你可以用sendmessage( ),再在wndproc( )中处理消息
largewang 2001-09-17
  • 打赏
  • 举报
回复
Why send message to itself?
Use Method, Ok!
another way:
Send message by it`s owner.
title 2001-09-17
  • 打赏
  • 举报
回复
帮你推一下!
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
我再推
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
to wantme:

Perform是TControl的函数,我是从TComponent继承的
wantme 2001-09-17
  • 打赏
  • 举报
回复
采用Perform函数可以
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
我推
Tense 2001-09-17
  • 打赏
  • 举报
回复
hehe
luxiaoban 2001-09-17
  • 打赏
  • 举报
回复
自定义消息

5,392

社区成员

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

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