Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2005.01.16;
Скачать: CL | DM;

Вниз

Командная строка   Найти похожие ветки 

 
Ralf ©   (2004-11-28 14:53) [0]

Как можно переслать командную строку из второго экземпляра программы в первый.


 
XProger ©   (2004-11-28 15:40) [1]

ShellExecute
ParamCount
ParamStr(1)
прочитай их описание


 
Игорь Шевченко ©   (2004-11-28 16:19) [2]


> Как можно переслать командную строку из второго экземпляра
> программы в первый.


WM_COPYDATA ?


 
Leonid Troyanovsky   (2004-11-29 15:58) [3]


> Ralf ©   (28.11.04 14:53)  
> Как можно переслать командную строку из второго экземпляра
> программы в первый.


Вот пример by Michel Winter:

On double click, the shell searches the registry whether the application
registered for that file type is able to receive DDE commands. If it
isn"t, the shell starts one application per file. If it is, the
application is started if it doesn"t run already, and after a while it
receives the file names.

Hopefully helpful example follows.

Our application should become informed on double clicks on files with
the extension ".myfile". Our application"s name is DdemlDemo.exe, and it
resides in c:\projects\dummy\DdemlDemo\.

First of all, we link the file extension to our application:

--------
REGEDIT4

[HKEY_CLASSES_ROOT\.myfile]
@="MyFile"

[HKEY_CLASSES_ROOT\MyFile]
@="My fine file"

[HKEY_CLASSES_ROOT\MyFile\Shell]
@=""

[HKEY_CLASSES_ROOT\MyFile\Shell\Open]
@="&Open"

[HKEY_CLASSES_ROOT\MyFile\Shell\Open\command]
@="C:\\Projects\\Dummy\\DdemlDemo\\DdemlDemo.exe"

[HKEY_CLASSES_ROOT\MyFile\Shell\Open\ddeexec]
@="[open(\"%1\")]"

[HKEY_CLASSES_ROOT\MyFile\Shell\Open\ddeexec\Application]
@="DdemlDemo"
--------

The DDE commands coming from the shell will look like

 [open("C:\00\test1.myfile")]

and we simply show them in a memo box. Parsing and reacting is left as
an exercise for the reader.

I want to point out that it"s possibly a good idea to do that DDE stuff
in an extra thread, namely if the application does some longer -time
calculations at startup or sometimes while executing. In that case, the
shell will assume (properly) that the appliaction doesn"t react any
more, and it will start a new one.

Here comes the code, without error handling.

--------
uses
 Ddeml;

const
 OurServiceName = "DdemlDemo";

var
 DdeInst: Integer;

function hsz2Str(Ahsz: HSZ): String;
var
 L: Integer;
begin
 Result := "";
 if Ahsz = 0 then exit;
 L := DdeQueryString(DdeInst, Ahsz, nil, 0, CP_WINANSI);
 if L <= 0 then exit;
 SetLength(Result, L);
 DdeQueryString(DdeInst, Ahsz, PChar(Result), L + 1, CP_WINANSI);
end;

function hDdeData2Str(AData: HDDEData): String;
var
 L: Integer;
begin
 Result := "";
 if AData = 0 then exit;
 L := DdeGetData(AData, nil, 0, 0);
 if L <= 0 then exit;
 SetLength(Result, L);
 DdeGetData(AData, PChar(Result), L, 0);
 L := Pos(#0, Result);
 if L > 0 then Delete(Result, L, MaxInt);
end;

function DdeFunc(CallType, Fmt: UINT; Conv: HConv; hsz1, hsz2: HSZ;
 Data: HDDEData; Data1, Data2: DWORD): HDDEData stdcall;
begin
 Result := 0;
 case CallType of
   XTYP_CONNECT: begin
     if SameText(hsz2Str(hsz1), SZDDESYS_TOPIC)
     and SameText(hsz2Str(hsz2), OurServiceName) then
       Result := 1;
   end;
   XTYP_EXECUTE: begin
     if SameText(hsz2Str(hsz1), SZDDESYS_TOPIC) then begin
       Form1.Memo1.Lines.Add(hDdeData2Str(Data));
       Result := DDE_FACK;
     end;
   end;
 end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
 DdeInitialize(DdeInst, DdeFunc,
   APPCLASS_STANDARD or CBF_SKIP_ALLNOTIFICATIONS, 0);
 DdeNameService(DdeInst,
   DdeCreateStringHandle(DdeInst, OurServiceName, CP_WINANSI),
   0, DNS_REGISTER);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
 DdeUninitialize(DdeInst);
end;
--------

--
С уважением,   LVT.


 
OSokin ©   (2004-11-30 19:46) [4]

Ж-жуть. Но у меня вообще вариант тоже жуткий: создать DC и передавать по нему данные цветом.


 
OSokin ©   (2004-11-30 19:47) [5]

Ж-жуть. Но у меня вообще вариант тоже жуткий: создать DC и передавать по нему данные цветом.



Страницы: 1 вся ветка

Текущий архив: 2005.01.16;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.047 c
1-1104189321
mozartw
2004-12-28 02:15
2005.01.16
Дайте ссылку на Fastlib


6-1098852987
Kniaz
2004-10-27 08:56
2005.01.16
Системное время на удаленной машине?


4-1101575440
Bora
2004-11-27 20:10
2005.01.16
Прямой доступ к портам в WinXP


4-1101562207
Express
2004-11-27 16:30
2005.01.16
Перевод компьютера в режим пониженного энергопотребления


1-1104518771
Cheguevara
2004-12-31 21:46
2005.01.16
Как создать в листбоксе итем содержащий путь к файлу