求救,明晨交货,关于文件关联,高分!(100分)

  • 主题发起人 主题发起人 guowzgyc
  • 开始时间 开始时间
G

guowzgyc

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大侠,偶有疑问相求:我做了一个应用程序,可以打开、保存一类扩展名
为'.slib'的文件,现在我可以做到将这种文件同我的应用关联起来,但是,我想
在资源管理器里通过双击该文件,在激活我的应用程序的同时,将该文件的数据读出
,怎么做?
 
修改注册表
比如:下面这样就可以用你的程序打开.txt文件,你模仿着做一下吧
HKEY_CLASSES_ROOT/txtfile/shell/open/command
"C:/YourAPP.exe %1"
 
大富翁名不副实哟
 
guowzgyc:
我说的不对吗?
 
const
cMyExt = '.db';
cMyFileType = 'Project1.FileType';
Reg := TRegistry.Create;
try
// Set the root key to HKEY_CLASSES_ROOT
Reg.RootKey := HKEY_CLASSES_ROOT;
// Now open the key, with the possibility to create
// the key if it doesn't exist.
Reg.OpenKey(cMyExt, True);
// Write my file type to it.
// This adds HKEY_CLASSES_ROOT/.abc/(Default) = 'Project1.FileType'
Reg.WriteString('', cMyFileType);
Reg.CloseKey;
// Now create an association for that file type
Reg.OpenKey(cMyFileType, True);
// This adds HKEY_CLASSES_ROOT/Project1.FileType/(Default)
// = 'Project1 File'
// This is what you see in the file type description for
// the a file's properties.
Reg.WriteString('', 'Project1 File');
Reg.CloseKey;
// Now write the default icon for my file type
// This adds HKEY_CLASSES_ROOT/Project1.FileType/DefaultIcon
// /(Default) = 'Application Dir/Project1.exe,0'
Reg.OpenKey(cMyFileType + '/DefaultIcon', True);
Reg.WriteString('', Application.ExeName + ',0');
Reg.CloseKey;
// Now write the open action in explorer
Reg.OpenKey(cMyFileType + '/Shell/Open', True);
Reg.WriteString('', '&Open');
Reg.CloseKey;
// Write what application to open it with
// This adds HKEY_CLASSES_ROOT/Project1.FileType/Shell/Open/Command
// (Default) = '"Application Dir/Project1.exe" "%1"'
// Your application must scan the command line parameters
// to see what file was passed to it.
Reg.OpenKey(cMyFileType + '/Shell/Open/Command', True);
Reg.WriteString('', '"' + Application.ExeName + '" "%1"');
Reg.CloseKey;
// Finally, we want the Windows Explorer to realize we added
// our file type by using the SHChangeNotify API.
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
finally
Reg.Free;
end;
以上是该注册表
然后在form.oncreate事件中增加
var filename:string;
filename:=paramtr(1);//filename是txt文件双击后传给你的程序的文件名
memo.load(filename);

 
对不起,不是针对您,您的答案正确但不全面,应该还用带参数运行的,paramstr,我已经解决了
 
多人接受答案了。
 
这样提取参数,
if ParamCount > 0 then
begin
for i:=1 to ParamCount do
Result := Result + ParamStr(i);
 
后退
顶部