const
  MM_REBOOTFLASHCOM = WM_USER + 101;
主程序
procedure MMRebootFlashCom(var Msg: TMessage); message MM_REBOOTFLASHCOM;procedure TmainForm.MMRebootFlashCom(var Msg: TMessage);
begin
  mmo1.lines.add('接收到消息!');
  //处理
  //DefaultHandler(Msg)
end;辅程序
procedure TForm1.btn1Click(Sender: TObject);
var
  SvrHandle: HWND;
begin
  msg.CmdType:=SC_MINIMIZE;
  SvrHandle := FindWindow(nil,  '主服务程序');
  if SvrHandle <> 0 then
  begin
    if PostMessage(SvrHandle,MM_REBOOTFLASHCOM,0,0 )  then
      ShowMessage('发送消息成功');
  end
  else
    ShowMessage('查找不到主程序');
end;
为什么主程序接收不到自定义消息
如果辅程序发送了一个WM_CLOSE,主程序是可以接收到的

解决方案 »

  1.   

    把PostMessage(SvrHandle,MM_REBOOTFLASHCOM,0,0 )
    改成 SendMessage(SvrHandle,MM_REBOOTFLASHCOM,0,0 )
      

  2.   

    PostMessage与SendMessage区别在于前者马上返回,后者则需要消息处理完后才返回的_____________________
    http://lysoft.7u7.net
      

  3.   

    欢迎加入Borland 一线程序员,参与群里技术讨论!欢迎女孩子,也欢迎男孩子参与技术讨论!群号15154361
      

  4.   

    用sendmessage和postMessage都不能接收到.
    用这两个发送WM_CLOSE都成功
    主要是主程序接收自定义消息的问题
      

  5.   

    1.要确定TmainForm的Caption为主服务程序;
    2.如果在同一程序中用SendMessage(TMainForm.handle,MM_REBOOTFLASHCOM,0,0 )
      

  6.   

    >>SvrHandle := FindWindow(nil,  '主服务程序');你必须用 TmainForm 的 caption 来查找要么,就要处理 Application的消息循环
      

  7.   

    注意,
    进程间通信时,如果向另外一个进程发送自定义的消息,必须在两个进程中都使用API:RegisterWindowMessage()来注册消息,否则,向另外一个进程发送消息时,不能收到。