关于参数处理,DELPHI有两个函数。
function paramcount 返回调用参数有几个。
function paramstr(index:integer):string;返回调用参数,
0代表应用程序,1代表第一个参数,依次类推。
所以你只需要在程序开始部分检查
if fileexists(params(1)) then begin
//检查是不是我的编辑器要处理的文件。
//用你的编辑器代码打开这个文件,就调用你的FILE OPEN菜单的代码就可以了。
end;
//向Windows系统注册一个文件扩展名关联
//例子:FS_FileSetAssociatedExeCuteable
// ('.test','实验文件','我的试验文件','text/test','mydelphi.exe',0);
//其中:FileType, FileDesc and MIMEType 是可以缺省不写的,用''代替.
//最后一个ICONINDEX是用你程序里头的那个图标来作为扩展文件的图标。是个0-N的整数
function FS_FileSetAssociatedExecutable(FileExt, Filetype, FileDesc, MIMEType, ExecutablePath: string;iconindex:word=0): Boolean;
var Reg: TRegistry;
begin
Result := False;
if (FileExt = '') or (ExecutablePath = '') then Exit;
if FileExt[1] <> '.' then FileExt := '.' + FileExt; // 'doc' -> '.doc'
if FileType = '' then FileType := Copy(FileExt, 2, Length(FileExt) - 1) + 'file';
Reg := TRegistry.Create;
try
Reg.RootKey := HKey_Classes_Root;
if not Reg.OpenKey(FileExt, True) then Exit;
Reg.WriteString('', FileType);
if MIMEType <> '' then
Reg.WriteString('Content Type', MIMEType); // Write MIMEType
Reg.CloseKey;
if not Reg.OpenKey(FileType, True) then Exit;
Reg.WriteString('', FileDesc); // write File Description
Reg.closekey;
if not Reg.OpenKey(FileType+'\'+'DefaultIcon', True) then Exit;
Reg.WriteString('', ExecutablePath+','+inttostr(iconindex));
Reg.closekey;
//if Pos('%1', ExecutablePath) = 0 then ExecutablePath := Trim(ExecutablePath) ;
// append the executable path with ' %1', ex. 'c:\winword.exe' -> 'c:\winword.exe %1'
if not Reg.OpenKey(FileType+'\shell\open\command', True) then Exit;
Reg.WriteString('', ExecutablePath+ ' %1'); // write the executable path
Reg.closekey;
finally
Reg.Free; // always free
end;
end;