I have found several methods to register a file type with my own application (double-clicking that file type in Windows Explorer looads that file in my application). Several are very old and seem to be deprecated, others are unclear and lack practical usage examples and thus are prone to misunderstandings.
@AndreasRejbrand has published an accepted solution here: How to associate a program with a file type, but only for the current user?
a) There is no complimentary way to UNREGISTER the file type.
b) It is not clear what'MyAppDataFile'means.
c) There are no practical usage examples.The
DSiWin32library contains the methodsDSiRegisterUserFileAssocandDSiUnregisterUserFileAssoc:
a)procedure DSiRegisterUserFileAssoc(const extension, progID, description, defaultIcon, openCommand: string);
aa) It is not clear what theprogIDparameter means.
ab) It is not clear how to pass thedefaultIconparameter.
ac) It is not clear how to pass theopenCommandparameter.
b)procedure DSiUnregisterUserFileAssoc(const progID: string);
ba) It is not clear what theprogIDparameter means and how to format it.
c) it would be nice to have a practical usage example.
BTW, this is the code from @AndreasRejbrand:
with TRegistry.Create do
try
RootKey := HKEY_CURRENT_USER;
if OpenKey('\Software\Classes\.myfile', true) then
WriteString('', 'MyAppDataFile');
if OpenKey('\Software\Classes\MyAppDataFile', true) then
WriteString('', 'My Very Own Text File Type');
if OpenKey('\Software\Classes\MyAppDataFile\DefaultIcon', true) then
WriteString('', 'C:\WINDOWS\notepad.exe');
if OpenKey('\Software\Classes\MyAppDataFile\shell\open\command', true) then
WriteString('', 'C:\WINDOWS\notepad.exe "%1"');
finally
Free;
end;
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
Can anyone provide CLEAR "fool-proof" practical usage examples for both approaches? Which one is better?
EDIT: With "practical USAGE examples" I mean: A procedure/function with example parameters.