消息的发送与接收? |
答題得分者是:william
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
Just an idea, not tested...
type PMyRec = ^TMyRec; TMyRec = record A: integer; B: double; end; const WM_MYMSG = WM_USER 1; ... var MyRec: TMyRec; ... SendMessage(RemoteHandle,WM_MYMGS,integer(@MyRec),0); ... type TForm1 = class (TForm) {...} procedure MyMsg(var Msg: TMessage); message WM_MYMSG; {...} end; procedure TForm1.MyMsg(var Msg: TMessage); var MyRec: PMyRec; begin MyRec := PMyRec(pointer(Msg.wParam)); ShowMessage(IntToStr(MyRec^.A)); end; |
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
〔Project1〕
program Project1; uses
Forms,
Unit1 in 'Unit1.pas' {Form1}
,Windows, Messages,Dialogs; const
hfck=wm_user+$1000;
appname='myname';
var
myhandle:hwnd;
str:string; {$R *.res} begin
str:='dddd';
myhandle:=findwindow(appname,nil);
if myhandle>0 then
begin
sendmessage(myhandle,hfck,integer(@str),0);
exit;
end
else
sendmessage(myhandle,hfck,integer(@str),1);
Application.Initialize;
Application.CreateForm(TForm1, Form1);
Application.Run;
end. unit Unit1; interface uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
const
hfck=wm_user $1000;
appname='myname';
type
TForm1 = class(TForm)
Memo1: TMemo;
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
procedure restorerequest(var msg:Tmessage);message hfck;
{ Public declarations }
end; var
Form1: TForm1; implementation {$R *.dfm} procedure TForm1.restorerequest(var msg:Tmessage);
var
pstr: Pstring;
begin
pstr := Pstring(pointer(Msg.wParam));
if pstr^<>'' then memo1.Lines.Add(pstr^);
end; procedure TForm1.Button1Click(Sender: TObject);
var
str:string;
begin
str:='ok';
sendmessage(handle,hfck,integer(@str),1);
end; end.
为什么button1有效,而红色部分
sendmessage(myhandle,hfck,integer(@str),0);
sendmessage(myhandle,hfck,integer(@str),1);
发送却无效? 注意:
消息肯定已经被接收,但是
pstr := Pstring(pointer(Msg.wParam));
if pstr^<>'' then memo1.Lines.Add(pstr^);
却不能将红色部分发送的字符接收
william 前辈:
又有点相关小问题请帮我解决一下,谢谢! 發表人 - sos_admin 於 2003/08/20 17:00:00
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
Sending message to another application? Although the message can be delivered, you cannot access other process's memory. There are many solution to this kind of inter process communication (e.g. socket, DDE, etc). Perhaps the easiest way is to create a physical data file to hold the data and then send the message to notify remote application reading the data file? If a physical file seems aweful, may I suggest memory mapped file? You may be interested in the API RegisterWindowMessage to generate a system wide unique message.
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
I think you send the message before your form is created..... so no messager handler for it when sending. For WM_COPYDATA, I have no experience of it and guess Windows do the tricks in this message since the data is only valid during the processing of the message.
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
sos_admin
版主 發表:121 回覆:697 積分:768 註冊:2003-07-23 發送簡訊給我 |
|
william
版主 發表:66 回覆:2535 積分:3048 註冊:2002-07-11 發送簡訊給我 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |