dpr:
uses
hSemaphore : DWORD;
hWindow : DWORD;
cdWork : TcsCopyDataStruct;
dwMSGFilepath : DWORD;
i : Integer;
dwMSGFilePath := RegisterWindowMessage('
{06007663-C0F6-4069-A835-D85AD31B5011}');
hSemaphore := CreateSemaphore(
nil,1,1,'
{E564BC8A-FBBE-42BF-B3A0-9C153FBBA03D}');
if not ((hSemaphore = 0)
or ((hSemaphore <> 0)
and (GetLastError = ERROR_ALREADY_EXISTS)))
then begin
Application.Initialize;
Application.Title := '
ITA';
Application.CreateForm(TMain_Window, Main_Window);
Application.Run;
end
else
begin
hWindow := FindWindow(
nil,'
ITA');
if hWindow <> 0
then begin
for i := 1
to ParamCount
do
begin
if (paramcount > 0)
and FileExists(paramstr(i))
then begin
cdWork.dwData := dwMSGFilepath;
cdWork.cbData := Length(paramstr(i)) + 1;
cdWork.lpData := AllocMem(cdWork.cbData);
try
CopyMemory(cdWork.lpData,@paramstr(i)[1],cdWork.cbData-1);
SendMessage(hWindow,WM_COPYDATA,0,lParam(@cdWork));
finally
FreeMem(cdWork.lpData,cdWork.cbData);
end;
end;
end;
end;
//Application.MessageBox('Programm läuft bereits','Hinweis',0);
end;
Main_Window:
public
procedure WndProc (
var Msg: TMessage);
override;
type
PcsCopyDataStruct = ^TcsCopyDataStruct;
TcsCopyDataStruct =
packed record
dwData : DWORD;
cbData : DWORD;
lpData : Pointer;
end;
procedure TMain_Window.WndProc(
var Msg: TMessage);
var
cdWork : PcsCopyDataStruct;
begin
if msg.Msg = WM_COPYDATA
then
begin
cdWork := PcsCopyDataStruct(msg.lParam);
MP3FileList.Add(PChar(cdWork.lpData));
exit;
end;
inherited;
end;
FORMSHOW:
for i := 1
to ParamCount
do
begin
if (paramcount > 0)
and FileExists(paramstr(i))
then
FileList.Add(paramstr(i));
end;