안녕하세요..
두개의 서로다른 프로그램 에서 서로 에게 메세지를 전달할려고 합니다..
메세지에 따른 이벤트를 발생하고요...
근데 ...한 프로그램에서 메세지를 보내면 메세지를 받은 프로그램에서
메세지를 두번 받는것이 보입니다...
메세지를 보내면 한번만 받을수 없나요...
메세지를 받으면 거기에 따른 이벤트를 발생하는데 ...두번 메세지를 받으면 ..
헉!!!! 난 어떻게...해요....
제가 한 메세지프로그램 소스 ...
프로그램 1..
unit ServerMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Label1: TLabel;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure OnAppMessage(var Msg : TMsg; var Handled : Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
RsMsgInt;
function BroadcastSystemMessage(Flags:DWORD; Recipients:PDWORD; uiMessage:UINT ; wParam:WPARAM; lParam:lPARAM)
:Longint ; stdcall; external 'user32.dll';
var
Recipients: DWORD = BSM_APPLICATIONS;
i : integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := OnAppMessage;
i := 0;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
BroadcastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE,@Recipients, Netplus_Message, 0, 1);//
end;
procedure TForm1.OnAppMessage(var Msg: TMsg; var Handled: Boolean);
var
sW,sL : integer;
begin
if Msg.message <> Netplus_Message then Exit;
sW := Msg.wParam;
sL := Msg.lParam;
Handled := True;
inc(i);
label1.Caption := Inttostr(i);
end;
end.
프로그램 2...
unit ClientMain;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Label1: TLabel;
procedure FormDestroy(Sender: TObject);
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
procedure OnAppMessage(var Msg : TMsg; var Handled : Boolean);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
uses
RsMsgInt;
function BroadcastSystemMessage(Flags:DWORD; Recipients:PDWORD; uiMessage:UINT ; wParam:WPARAM; lParam:lPARAM)
:Longint ; stdcall; external 'user32.dll';
var
Recipients: DWORD = BSM_APPLICATIONS;
i : integer;
procedure TForm1.FormCreate(Sender: TObject);
begin
Application.OnMessage := OnAppMessage;
i := 0;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
BroadcastSystemMessage(BSF_IGNORECURRENTTASK or BSF_POSTMESSAGE,@Recipients, Netplus_Message,
1,
1);
end;
procedure TForm1.OnAppMessage(var Msg: TMsg; var Handled: Boolean);
var
sW,sL : integer;
begin
if Msg.message <> Netplus_Message then Exit;
Handled := True;
sW := Msg.wParam;
sL := Msg.lParam;
case sL of
0: Beep;//Showmessage(intTostr(sW) + '--' + intTostr(sL));
1: Beep;//Showmessage(intTostr(sW) + '--' + intTostr(sL));
end;
inc(i);
label1.Caption := Inttostr(i);
end;
end.
공동유닛....
unit RsMsgInt;
interface
var
Netplus_Message : Cardinal;
implementation
uses
WinProcs;
const
str_Message = 'kkkkkkkpppooo';
initialization
Netplus_Message := RegisterWindowMessage(str_Message);
end.