두개의 실행모듈간 interface 가 필요합니다.
팁에 게시된 오병종님의 Source 를 참조했으나 잘안되어서.....
Delphi V4 이고요 os는 Windows me 입니다.......
Sned.exe Source
-----------------------------------------
unit Send;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
WinTypes, WinProcs, StdCtrls, Grids, ExtCtrls, Buttons, shellapi;
type
TsendF = class(TForm)
Label1: TLabel;
Button1: TButton;
Memo1: TMemo;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
sendF: TsendF;
implementation
{$R *.DFM}
procedure TsendF.Button1Click(Sender: TObject);
var
hWndMe : HWnd;
str1,str2 : string;
begin
str1 := '12345';
hwndme := FindWindow('TApplication', pchar(str1));
if (hWndMe <> 0) then
begin
showmessage(' 이미 수행중입니다.!!');
SetactiveWindow(hWndMe);
BringWindowToTop(hWndMe);
ShowWindow(hWndMe, SW_SHOWNORMAL);
exit;
end;
str2 := 'project2.exe ' + '12345 ';
shellExecute(0,'',PChar(ExtractFileDirApplication.ExeName) +
'\Project2.exe'), PChar(str2),'',SW_SHOWNORMAL);
end;
procedure TsendF.FormCreate(Sender: TObject);
var
hWndMe : HWnd;
begin
hwndme := FindWindow('TApplication','send');
if (hWndMe <> 0) then
begin
showmessage(' 이미 send 프로그램이 수행중입니다.!!');
SetForegroundWindow(hWndMe);
SetactiveWindow(hWndMe);
BringWindowToTop(hWndMe);
ShowWindow(hWndMe, SW_SHOWNORMAL);
exit;
end
else
begin
Application.Title := 'send';
hwndme := FindWindow('TApplication','send');
BringWindowToTop(hWndMe);
end;
end;
procedure TsendF.Button4Click(Sender: TObject);
var hWndMe : HWnd;
str1 : string;
begin
str1 := '12345';
hwndme := FindWindow('TApplication', pchar(str1));
if (hWndMe <> 0) then
begin
SendMessage(hwndme, WM_USER + 1,1,1 );
// SendMessage(hwndme, WM_CLOSE,0,0 );
// WM_CLOSE 는 잘됨.....
end;
end;
Receive.exe Source
-----------------------------------------
unit Receive;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
Dialogs, WinTypes, WinProcs, StdCtrls, Grids, ExtCtrls, Buttons,
shellapi;
type
TReceiveF = class(TForm)
Button1: TButton;
Memo1: TMemo;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure UserFunction(var AUserMessage: TMessage); Message
WM_USER + 1;
private
{ Private declarations }
public
{ Public declarations }
end;
var
ReceiveF: TReceiveF;
implementation
{$R *.DFM}
procedure TReceiveF.UserFunction(var AUserMessage: TMessage);
var
begin
showmessage('receive');
end;
procedure TReceiveF.FormCreate(Sender: TObject);
var
hWndMe : HWnd;
d_strTmp : string;
begin
d_strTmp := paramstr(2);
hwndme := FindWindow('TApplication',pchar(d_strTmp));
if (hWndMe <> 0) then
begin
showmessage(' 이미 rec 프로그램이 수행중입니다.!!');
SetForegroundWindow(hWndMe);
SetactiveWindow(hWndMe);
BringWindowToTop(hWndMe);
ShowWindow(hWndMe, SW_SHOWNORMAL);
exit;
end
else
begin
Application.Title := d_strTmp;
hwndme := FindWindow('TApplication',pchar(d_strTmp));
BringWindowToTop(hWndMe);
end;
end;
end.end.
var hWndMe : HWnd;
str1 : string;
begin
str1 := '12345';
hwndme := FindWindow('TReceiveF', nil);
if (hWndMe <> 0) then
begin
SendMessage(hwndme, WM_USER + 1,1,1 );
// SendMessage(hwndme, WM_CLOSE,0,0 );
// WM_CLOSE 는 잘됨.....
end;
end;
FindWindow에서 첫번째 인자가 클래스 명이니까
메시지를 받는 폼의 클래스 명을 입력해야하지 않나요?
아니면 두번째 인자인 윈도우 이름을 맞춰주시던지...
즐프하세요..