Текущий архив: 2007.07.08;
Скачать: CL | DM;
Вниз
Как передать программе имя открываемого файла? Найти похожие ветки
← →
NervoVred (2007-06-16 22:14) [0]Не уверен с точностью формулировки вопроса, но задача поставлена такая: научить программу открывать файлы, по которым сделан клик мышкой в окне Эксплорера. Т.е. не загружать программу каким-нибудь OpenDialog"ом, а щелкнуть по файлу. Программа после этого должна загрузиться и открыть требуемый файл.
← →
MsGuns © (2007-06-16 22:49) [1]
procedure TfrmMain.FormShow(Sender: TObject);
begin
if ParamCount>0 then CDSFileName := ParamStr(1);
end;
← →
Rial © (2007-06-16 23:11) [2]При запуске в 1м параметре будет передаваться имя файла.
Как зарегистрировать файл, можно посмотреть в приведенном
ниже модуле. Там все ясно как божий день, разберись.
Unit
Registration;
Interface
Uses
Windows;
{
Регистариция приложение с указанием имени исполняемого файла,
именен папки приложения, расширением, названием программы, командой открытия (напр. "%1")
Обратите внимание, что команду открытия необходимо брать в двойные кавычки!
Версия 1.1. [9.02.2005]
}
Const
//место для ключика по умолчанию
HKey_Default = HKey_Local_Machine;
//Регистрация расширения
procedure rsrCreateFileReg(Const sIconFileName, sSectionName, sFileExt, sFileLabel, sOpenCommand : String;
Const nIconNumber : Integer; Const bNoOpen : Boolean);
//Регистрация приложения
procedure rsrCreateSoftReg(Const sExeName, sSoftName : String; Const hkRootKey : HKEY = HKey_Default);
//Удаление регистрации расширения
procedure rsrDeleteFileReg(Const sSectionName, sFileExt : String; Const hkRootKey : HKEY = HKey_Default);
//Удаление регистрации расширения
procedure rsrDeleteSoftReg(Const sSoftName : String; Const hkRootKey : HKEY = HKey_Default);
//Получение установочной директории
function rsrGetInstallPath(Const sSoftName : String; Const hkRootKey : HKEY = HKey_Default) : String;
Implementation
Uses
SysUtils, Registry;
Const SoftPath = "\Software\";
InstallStr = "InstallPath";
function rsrGetInstallPath(Const sSoftName : String; Const hkRootKey : HKEY = HKey_Default) : String;
begin
Result :=GetCurrentDir;
With TRegistry.Create do
Try
RootKey :=hkRootKey;
If (OpenKey(SoftPath + sSoftName, False))then begin
Result :=ReadString(InstallStr);
CloseKey;
end;
Finally
Free;
end;
end;
procedure rsrCreateSoftReg(Const sExeName, sSoftName : String; Const hkRootKey : HKEY = HKey_Default);
begin
With TRegistry.Create do
Try
RootKey :=hkRootKey;
CreateKey(SoftPath + sSoftName);
If OpenKey(SoftPath + sSoftName, False) then begin
WriteString(InstallStr, ExtractFileDir(sExeName));
CloseKey;
end;
Finally
Free;
end;
end;
procedure rsrCreateFileReg(Const sIconFileName, sSectionName, sFileExt, sFileLabel, sOpenCommand : String;
Const nIconNumber : Integer; Const bNoOpen : Boolean);
Var
Reg : TRegistry;
procedure Step(Const Path, Name, Value : String);
begin
With Reg do
If (OpenKey(Path, True))then begin
WriteString(Name, Value);
CloseKey;
end;
end;
begin
Reg :=TRegistry.Create;
Try
Reg.RootKey :=HKey_Classes_Root;
Step("\" + sFileExt, "", sSectionName);
Step(sSectionName, "", sFileLabel);
If (bNoOpen)then
Step("\" + sSectionName, "NoOpen", "");
Step("\" + sSectionName + "\DefaultIcon", "", sIconFileName + "," + IntToStr(nIconNumber));
If (sOpenCommand <> "")then
Step("\" + sSectionName + "\Shell\Open\Command", "", """ + sIconFileName + "" " + sOpenCommand);
Finally
Reg.Free;
end;
end;
procedure rsrDeleteFileReg(Const sSectionName, sFileExt : String; Const hkRootKey : HKEY = HKey_Default);
begin
With TRegistry.Create do
Try
RootKey :=hkRootKey;
DeleteKey("\" + sFileExt);
DeleteKey(sSectionName);
Finally
Free;
end;
end;
procedure rsrDeleteSoftReg(Const sSoftName : String; Const hkRootKey : HKEY = HKey_Default);
begin
With TRegistry.Create do
Try
RootKey :=hkRootKey;
DeleteKey(SoftPath + sSoftName);
Finally
Free;
end;
end;
end.
Страницы: 1 вся ветка
Текущий архив: 2007.07.08;
Скачать: CL | DM;
Память: 0.48 MB
Время: 0.044 c