求救,关于注册文件后的打开问题(50分)

  • 主题发起人 主题发起人 kingqc
  • 开始时间 开始时间
K

kingqc

Unregistered / Unconfirmed
GUEST, unregistred user!
文件注册成功后,打开程序是文件未能载入,为什么?
下面是我的源程序
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 itdo
esn'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;
 
注册倒是成功了,关键问题是你的主程序中Project1.exe是否对paramstr(1)处理了?
 
对呀, 你的程序还要处理传入的参数才行.在资源管理器中双击这个文件,
操作系统会把这个文件名(含路径)发到关联程序的第二个参数即paramstr(1)中.
所以要用如memo1.lines.loadfromfile(paramstr(1))之类的语句装入.
 
我要打开一个bmp文件
我的原码中该怎么改?
我在资源管理器中打开的时候
image.picture.loadfilefrom(paramstr(1))
但paramstr(1)放在我那段代码的那啊
能具体点吗?不胜感激!
 
放在 form.oncreate事件中
eg
:
procedure tform.formcreate
begin
if paramstr(1)<>''then
memo.loadfile(paramstr(1));
end;
 
多人接受答案了。
 
后退
顶部