線上訂房服務-台灣趴趴狗聯合訂房中心
發文 回覆 瀏覽次數:2672
推到 Plurk!
推到 Facebook!

消息的发送与接收?

答題得分者是:william
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#1 引用回覆 回覆 發表時間:2003-08-20 13:32:57 IP:61.155.xxx.xxx 未訂閱
消息的发送与接收? 怎么利用消息来传送 字符串(string)类型、记录类型、数组、variant、其它如枚举、集合等自定义类型!并且,怎样接收使用! 谢谢!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#2 引用回覆 回覆 發表時間:2003-08-20 14:09:37 IP:147.8.xxx.xxx 未訂閱
消息 == Windows Message? wParam and lParam are 4 byte longint. So anything other than integer shall be sent using a pointer pointing to the value like Windows API does.
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#3 引用回覆 回覆 發表時間:2003-08-20 14:58:16 IP:61.155.xxx.xxx 未訂閱
多谢 william 前辈相助! 就是指Windows Message 用psotmessage、sendmessage等发送的消息。 您上面所讲是要用到pointer做中间桥梁吗?可否举个示例!谢谢!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#4 引用回覆 回覆 發表時間:2003-08-20 15:17:51 IP:147.8.xxx.xxx 未訂閱
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

發送簡訊給我
#5 引用回覆 回覆 發表時間:2003-08-20 16:03:07 IP:61.155.xxx.xxx 未訂閱
william 前辈,多谢了! 通过您的程式我也知道其它数据类型的传输方法!
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#6 引用回覆 回覆 發表時間:2003-08-20 16:54:59 IP:61.155.xxx.xxx 未訂閱
〔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

發送簡訊給我
#7 引用回覆 回覆 發表時間:2003-08-20 17:11:53 IP:147.8.xxx.xxx 未訂閱
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

發送簡訊給我
#8 引用回覆 回覆 發表時間:2003-08-20 17:26:02 IP:61.155.xxx.xxx 未訂閱
william 兄:    您说的也对,这些方法我也想过! 但是,我上面至少说在第一次启动的时候,它findwindow(appname,nil); 应该是自己handle,并且应该共享自身的内存区域,应该可以实现sendmessage的 还有,我看一些文章使用TCOPYDATASTRUCT 类型 procedure GetMessData(var message : TWMCopyData); message WM_COPYDATA ; 也可以实现不通exe之间的消息传递!
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#9 引用回覆 回覆 發表時間:2003-08-20 17:57:47 IP:147.8.xxx.xxx 未訂閱
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

發送簡訊給我
#10 引用回覆 回覆 發表時間:2003-08-21 07:52:49 IP:61.155.xxx.xxx 未訂閱
I THINK,YOU ARE RIGHT! 但是我想在form中取得定义在Project文件中变量str:string值,我该怎么办? 谢谢!
sos_admin
版主


發表:121
回覆:697
積分:768
註冊:2003-07-23

發送簡訊給我
#11 引用回覆 回覆 發表時間:2003-08-21 10:13:34 IP:61.155.xxx.xxx 未訂閱
多谢william前辈: 我已经找到解决方法了!谢谢! 不知道这种解决方法到底好不好? http://delphi.ktop.com.tw/topic.php?TOPIC_ID=36089
william
版主


發表:66
回覆:2535
積分:3048
註冊:2002-07-11

發送簡訊給我
#12 引用回覆 回覆 發表時間:2003-08-21 10:31:26 IP:147.8.xxx.xxx 未訂閱
It works fine 
系統時間:2024-05-06 18:02:26
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!