Вниз
Скачать: 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 вся ветка

Скачать: CL | DM;



Память: 0.46 MB
Время: 0.033 c
14-1103900292
guest_Dmitry
2004-12-24 17:58
2005.01.16
Какие бумаги должны оформляться на замену железа?


1-1104133498
hgd
2004-12-27 10:44
2005.01.16
тип Extended


3-1103111618
Heretic
2004-12-15 14:53
2005.01.16
Проблемы с EhLib (EhDbGrid) при связи таблиц


1-1104692206
TechnoDreamer
2005-01-02 21:56
2005.01.16
Добавление элемента в TreeView без потери сортировки


1-1104155784
Gear
2004-12-27 16:56
2005.01.16
Delphi 2005 и Compact Framework .NET




   Наверх