消息的参数为什么修改不了? ( 积分: 150 )

  • 主题发起人 主题发起人 let_it_be
  • 开始时间 开始时间
L

let_it_be

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

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

const
cm_mymsg = wm_user+1;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure cmMyMsg(var msg: TMessage); message cm_mymsg;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
r: integer;
begin
r:=1;
sendmessage(handle, cm_mymsg, 0, r);

[red]showmessage(inttostr(r)); R 为什么 不等于 11, 还是 1。[/red]
end;

procedure TForm1.cmMyMsg(var msg: TMessage);
begin
msg.WParam:=11; [blue]这里改变[/blue]
msg.LParam:=11;
end;

end.
 
unit Unit1;

interface

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

const
cm_mymsg = wm_user+1;

type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure cmMyMsg(var msg: TMessage); message cm_mymsg;
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var
r: integer;
begin
r:=1;
sendmessage(handle, cm_mymsg, 0, r);

[red]showmessage(inttostr(r)); R 为什么 不等于 11, 还是 1。[/red]
end;

procedure TForm1.cmMyMsg(var msg: TMessage);
begin
msg.WParam:=11; [blue]这里改变[/blue]
msg.LParam:=11;
end;

end.
 
当然不行的,SendMessage函数的参数是传值,不是传引用.当然是不能返回来的,你可以用全局变量,或者别的方法来实现.
 
不要告诉我用什么什么别的方法,我知道用全局变量 可以, 我只是想知道为什么,还有,我看到有 WM_getText 等等, 是可以的喔
 
直接用消息传个地址过去应该可以吧
procedure TForm1.Button1Click(Sender: TObject);
var
r: integer;
begin
r:=1;
sendmessage(handle, cm_mymsg, 0, integer(@r));

[red]showmessage(inttostr(r)); R 为什么 不等于 11, 还是 1。[/red]
end;

procedure TForm1.cmMyMsg(var msg: TMessage);
begin
(PInteger(msg.LParam))^:=11;
end;

end.
 
接受答案了.
 
后退
顶部