如何定义新扩展名的文件类型?(100分)

  • 主题发起人 主题发起人 henry3
  • 开始时间 开始时间
H

henry3

Unregistered / Unconfirmed
GUEST, unregistred user!
如何定义新扩展名的文件类型,并且用特定的应用程序打开。<br>(应该是在注册表中,我看到HKEY_CLASSES_ROOT,下有各种文件类型。)<br>
 
HKEY_CLASSES_ROOT/.xxx (xxx是文件扩展名),默认键值是扩展名描述。
 
补充:Sample:<br>HKEY_CLASSES_ROOT/.xxx 默认键值 myfile<br>HKEY_CLASSES_ROOT/myfile/DefaultIcon 默认键值 Icon &nbsp;Locate<br>HKEY_CLASSES_ROOT/myfile/Shell/Open/Command 默认键值 Applicatin Path and name<br>为什么不用资源管理器的新建文件类型?<br>是想在程序中使用么?<br>如果这样,好象还要调用某个API通知Windows注册表已经更新<br>不然关联图标在Reboot后才生效.
 
我是想在安装程序时使用。<br>(自己写的安装程序)
 
那你就用TRegistry把这些东西写到注册表里面就可以了!<br>比如,你做安装程序,需要关联一个自定义的.abc类型:<br>这样就可以在用户双击.abc文件时,默认用YourExeFile<br>打开,当然,记住在程序卸载的时候把这些东西清除掉。<br>procedure TMainForm.AddABC;<br>var<br>&nbsp; reg: TRegistry;<br>begin<br>&nbsp; reg := TRegistry.Create;<br>&nbsp; reg.RootKey := HKEY_CLASSES_ROOT;<br>&nbsp; reg.OpenKey('.abc', true);<br>&nbsp; reg.WriteString('', 'abc_auto_file');<br>&nbsp; reg.CloseKey;<br>&nbsp; reg.OpenKey('abc_auto_file/shell/open/command', true);<br>&nbsp; reg.WriteString('', '"' + YourExeFile + '" "%1"');<br>&nbsp; reg.CloseKey;<br>&nbsp; reg.Free;<br>end;<br>
 
=======================listen
 
to beta:<br>(1)程序卸载时,如何清除<br>(2)Netants在没有下载前,好象使用了!!!扩展名,此时图标是蚂蚁,可是我们在资源管理器仍然<br>看到是不带!!!扩展名的文件名称,请问,他是如何实现的
 
1.<br>var<br>&nbsp; reg: TRegistry;<br>begin<br>&nbsp; reg := TRegistry.Create;<br>&nbsp; reg.RootKey := HKEY_CLASSES_ROOT;<br>&nbsp; reg.DeleteKey('.abc');<br>&nbsp; reg.DeleteKey('abc_auto_file');<br>&nbsp; reg.Free;<br>end;<br><br>2.因为我不用蚂蚁,所以不是很清楚你说的意思,请你再说详细一点。<br>
 
to Bate:<br>请看:http://www.delphibbs.com/delphibbs/dispq.asp?LID=518711
 
要改注册表的啊。
 
给你两个函数,注册、卸载就方便了[:)]<br><br>function RegAssociatedExec(FileExt, Filetype, FileDescription, MIMEType, Icon,<br>&nbsp; ExecName: String): Boolean;<br>begin<br>&nbsp; Result := False;<br>&nbsp; if (FileExt = '') or (ExecName = '') then<br>&nbsp; &nbsp; Exit;<br><br>&nbsp; with TRegistry.Create do<br>&nbsp; begin<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey:=HKEY_CLASSES_ROOT;<br>&nbsp; &nbsp; &nbsp; if not OpenKey(FileExt, True) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br><br>&nbsp; &nbsp; &nbsp; WriteString('', FileType);<br>&nbsp; &nbsp; &nbsp; if MIMEType &lt;&gt; '' then<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteString('Content Type', MIMEType);<br>&nbsp; &nbsp; &nbsp; CloseKey;<br><br>&nbsp; &nbsp; &nbsp; if not OpenKey(FileType, True) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; WriteString('', FileDescription);<br>&nbsp; &nbsp; &nbsp; CloseKey;<br><br>&nbsp; &nbsp; &nbsp; if Icon&lt;&gt;'' then<br>&nbsp; &nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; &nbsp; if not OpenKey(FileType+'/DefaultIcon', True) then<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; &nbsp; WriteString('', Icon);<br>&nbsp; &nbsp; &nbsp; &nbsp; CloseKey;<br>&nbsp; &nbsp; &nbsp; end;<br><br>&nbsp; &nbsp; &nbsp; if not OpenKey(FileType+'/Shell/Open/Command', True) then<br>&nbsp; &nbsp; &nbsp; &nbsp; Exit;<br>&nbsp; &nbsp; &nbsp; WriteString('', ExecName);<br>&nbsp; &nbsp; &nbsp; CloseKey;<br><br>&nbsp; &nbsp; &nbsp; SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>procedure UnRegAssociatedExec(FileExt, FileType: String);<br>begin<br>&nbsp; with TRegistry.Create do<br>&nbsp; begin<br>&nbsp; &nbsp; try<br>&nbsp; &nbsp; &nbsp; RootKey:=HKEY_CLASSES_ROOT;<br>&nbsp; &nbsp; &nbsp; if KeyExists(FileExt) then<br>&nbsp; &nbsp; &nbsp; &nbsp; DeleteKey(FileExt);<br>&nbsp; &nbsp; &nbsp; if KeyExists(FileType) then<br>&nbsp; &nbsp; &nbsp; &nbsp; DeleteKey(FileType);<br>&nbsp; &nbsp; finally<br>&nbsp; &nbsp; &nbsp; Free;<br>&nbsp; &nbsp; end;<br>&nbsp; end;<br>end;<br><br>例:<br>RegAssociatedExec('.txt','txtfile','文本文档','text/plain',%SystemRoot%/system32/shell32.dll,-152','%SystemRoot%/system32/NOTEPAD.EXE %1');<br>
 
直接写个*.reg文件得啦。安装是使用程序启动就可以了,有错误也好改正。<br>注册表文件格式:<br>Regedit 4<br><br>[HKCR/abc_auto_file/shell/open/command]<br>"your program"='%SystemRoot%/system32/NOTEPAD.EXE %1' &nbsp; ;新建<br>"your program"=- &nbsp;;删除项<br><br>[-HKCR/abc_auto_file/shell/open/command] //删除子键
 
with Field do<br>&nbsp; begin<br>&nbsp; &nbsp; if not (State in dsWriteModes) then DatabaseError(SNotEditing, Self);<br>&nbsp; &nbsp; GetActiveRecBuf(RecBuf);<br>&nbsp; &nbsp; if FieldNo &gt; 0 then<br>&nbsp; &nbsp; begin<br>&nbsp; &nbsp; &nbsp; if ReadOnly and not (State in [dsSetKey, dsFilter]) then<br>&nbsp; &nbsp; &nbsp; &nbsp; DatabaseErrorFmt(SFieldReadOnly, [DisplayName]);<br>&nbsp; &nbsp; &nbsp; Validate(Buffer);<br>&nbsp; &nbsp; &nbsp; if FModifiedFields.IndexOf(Field) = -1 then<br>&nbsp; &nbsp; &nbsp; &nbsp; FModifiedFields.Add(Field);<br>&nbsp; &nbsp; end;<br>&nbsp; &nbsp; if Buffer = nil then<br>&nbsp; &nbsp; &nbsp; Data := Null else<br>&nbsp; &nbsp; &nbsp; BufferToVar(Data);<br>&nbsp; &nbsp; PVariantList(RecBuf+SizeOf(TRecInfo))[Field.Index] := Data;<br>&nbsp; &nbsp; if not (State in [dsCalcFields, dsInternalCalc, dsFilter, dsNewValue]) then<br>&nbsp; &nbsp; &nbsp; DataEvent(deFieldChange, Longint(Field));<br>&nbsp; end;<br>end;
 
后退
顶部