Форум: "WinAPI";
Текущий архив: 2005.01.30;
Скачать: [xml.tar.bz2];
ВнизПередача "сигнала" программе. Найти похожие ветки
← →
mefisto (2004-12-07 22:35) [0]Есть проблема!!! Моя программа запущена, и висит в трэе. Как мне например из Internet Explorera вызвать какую-то процедуру в программе так что бы она (программа) не перезапускалась. И если можна ответить написавши примерчик :)
Заранее благодарен !!!!!!!!!!!!!!!!!!!!!!
← →
Rouse_ © (2004-12-07 22:46) [1]> Как мне например из Internet Explorera вызвать какую-то
> процедуру в программе
Для начала придется внедриться в эксплорер...
Ну а вызов процедуры организовать можно, к примеру, банальным SendMessage с заранее зарегистрированным сообщением...
Примеры и того и другого можно найти в FAQ...
← →
Leonid Troyanovsky (2004-12-08 14:41) [2]
> mefisto (07.12.04 22:35)
> Есть проблема!!! Моя программа запущена, и висит в трэе.
> Как мне например из Internet Explorera вызвать какую-то
> процедуру в программе так что бы она (программа) не перезапускалась.
Martin Binder schrieb:
>
> I have written an editor that I don"t want to allow multiple copies to run
> at once. So if I already have an instance of my editor running, and another
> instance is started, I want to halt the second instance and pass the initial
> instance any command-line parameters from the second instance. I think I
> can use DDE to accomplish this, but I"m not quite sure how. Anybody have a
> simple example of this, or at least point me in the right direction?
Here"s an older article with a simple DDE example:
Raymond Kennington schrieb:
>
> With an MDI app the user can select several docs in Explorer, press Enter, and all the
> documents are opened in the same instance of an application.
Yes.
> However Windows attempts to open one instance of my MDI application for each document
> selected.
Yes. Windows doesn"t know that your application is able to handle
multiple files.
> I would be able to easily process these files (through ParamStr and ParamCount) if the
> entire list of files were passed to my application.
>
> Is it possible to retrieve the entire collection of selected files in a single command
> line string?
No.
> If not, how does one usually approach this problem?
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;
--------
-Michael
--
С уважением, LVT.
Страницы: 1 вся ветка
Форум: "WinAPI";
Текущий архив: 2005.01.30;
Скачать: [xml.tar.bz2];
Память: 0.47 MB
Время: 0.03 c