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,主程序是可以接收到的
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,主程序是可以接收到的
改成 SendMessage(SvrHandle,MM_REBOOTFLASHCOM,0,0 )
http://lysoft.7u7.net
用这两个发送WM_CLOSE都成功
主要是主程序接收自定义消息的问题
2.如果在同一程序中用SendMessage(TMainForm.handle,MM_REBOOTFLASHCOM,0,0 )
进程间通信时,如果向另外一个进程发送自定义的消息,必须在两个进程中都使用API:RegisterWindowMessage()来注册消息,否则,向另外一个进程发送消息时,不能收到。