关于应用程序之间发送和处理消息!(100分)

  • 主题发起人 主题发起人 almeidar
  • 开始时间 开始时间
A

almeidar

Unregistered / Unconfirmed
GUEST, unregistred user!
使用<br>hWnd=FindWindow()<br>PostMessage(hWnd,MSG,0,0)<br>方法是在知道指定应用程序的情况下,如果需要广播一个消息,使能够响应的其他应用程序<br>自动响应,应该如何写代码?<br>我不知道RegisterWindowMessage应该写在什么地方?[:D]
 
用消息广播可以实现<br>var<br>&nbsp; &nbsp;s : array[0..64] of char;<br>begin<br>&nbsp; &nbsp; StrCopy(S, 'windows');<br>&nbsp; &nbsp; SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, LongInt(@S));<br>end;<br>
 
antic_ant,获得30分,<br>能不能解释一下,如何在其他应用程序里响应此消息?
 
用函数传递不行吗?
 
Tense,不明白怎么用函数传递?[8D]
 
unit Unit1;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br>const<br>&nbsp; SX_MYMESSAGE=WM_USER+100;<br>type<br>&nbsp; TSendMsg = class(TForm)<br>&nbsp; &nbsp; procedure FormCreate(Sender: TObject);<br>&nbsp; private<br>{ Private declarations }<br>&nbsp; public<br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; SendMsg: TSendMsg;<br><br>implementation<br><br>{$R *.DFM}<br><br>procedure TSendMsg.FormCreate(Sender: TObject);<br>var Myhandle:HWND;<br>begin<br>&nbsp;Myhandle:= FindWindow(nil, 'GetMsg');<br>&nbsp;if MyHandle &lt;&gt; 0 then<br>&nbsp; &nbsp; SendMessage( Myhandle,SX_MYMESSAGE,0,0) &nbsp; &nbsp; <br>end;<br>end.<br><br>unit Unit2;<br><br>interface<br><br>uses<br>&nbsp; Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;<br>const<br>&nbsp;SX_MYMESSAGE=WM_USER+100;<br>type<br>&nbsp; TGetMsg = class(TForm)<br>&nbsp; private<br>procedure get_message(var Message:TMessage);Message SX_MYMESSAGE;<br>&nbsp; &nbsp; { Private declarations }<br>&nbsp; public<br><br>&nbsp; &nbsp; { Public declarations }<br>&nbsp; end;<br><br>var<br>&nbsp; GetMsg: TGetMsg;<br><br>implementation<br><br>{$R *.DFM}<br>procedure TGetMsg.get_message(var Message: TMessage);<br>begin<br>&nbsp; MessageDlg('she turned me into a newt!',mtInformation,[mbOk],0);<br>end;<br>end.<br>&nbsp;
 
pingbaoshi,你写得代码没错。我以前就是用的这种方法,现在的情况是,<br>发送广播消息,不必FindWindow,只需要能响应该消息的程序能接收和响应即可。
 
application.OnMessage<br>事件中处理,如果是你自定义的消息就可以进行处理了
 
用SendMessage + WM_COPYDATA也可以吧<br><br>发送方:SendMessage(MyAqua, WM_COPYDATA, 0, (LPARAM)(&amp;SendData));<br>接收方:<br>&nbsp; &nbsp; &nbsp; &nbsp;void __fastcall TForm1::RelateOpenFile(TMessage &amp;Msg)<br>&nbsp; &nbsp; &nbsp; &nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;AnsiString ARelateFile = (char*)(((TCopyDataStruct*)(Msg.LParam))-&gt;lpData);<br>&nbsp; &nbsp; &nbsp; &nbsp;}<br>
 
好象是要在每个应用程序中对消息进行注册才能响应的吧。在delphi深度历险上有个例子,<br>但是是繁体的,现在还在看着呢,8)
 
有结果通知我一声。
 
后退
顶部