TIP [DELPHI] : Associare un estensione File alla vs aplicazione da codice
Associare un estensione file alla vostra applicazione :
1 |
Procedure <b>RegisterFileType</b>(cMyExt, cMyFileType, cMyDescription, ExeName: string; IcoIndex: integer; DoUpdate: boolean = false); |
1 |
var |
1 |
Reg: TRegistry; |
1 |
begin |
1 |
Reg := TRegistry.Create; |
1 |
try |
1 |
Reg.RootKey := HKEY_CLASSES_ROOT; |
1 |
Reg.OpenKey(cMyExt, True); |
1 |
// Write my file type to it. |
1 |
// This adds HKEY_CLASSES_ROOT\.abc\(Default) = 'Project1.FileType' |
1 |
Reg.WriteString('', cMyFileType); |
1 |
Reg.CloseKey; |
1 |
// Now create an association for that file type |
1 |
Reg.OpenKey(cMyFileType, True); |
1 |
// This adds HKEY_CLASSES_ROOT\Project1.FileType\(Default) |
1 |
// = 'Project1 File' |
1 |
// This is what you see in the file type description for |
1 |
// the a file's properties. |
1 |
Reg.WriteString('', cMyDescription); |
1 |
Reg.CloseKey; // Now write the default icon for my file type |
1 |
// This adds HKEY_CLASSES_ROOT\Project1.FileType\DefaultIcon |
1 |
// \(Default) = 'Application Dir\Project1.exe,0' |
1 |
Reg.OpenKey(cMyFileType + '\DefaultIcon', True); |
1 |
Reg.WriteString('', ExeName + ',' + IntToStr(IcoIndex)); |
1 |
Reg.CloseKey; |
1 |
// Now write the open action in explorer |
1 |
Reg.OpenKey(cMyFileType + '\Shell\Open', True); |
1 |
Reg.WriteString('', '&Open'); |
1 |
Reg.CloseKey; |
1 |
// Write what application to open it with |
1 |
// This adds HKEY_CLASSES_ROOT\Project1.FileType\Shell\Open\Command |
1 |
// (Default) = '"Application Dir\Project1.exe" "%1"' |
1 |
// Your application must scan the command line parameters |
1 |
// to see what file was passed to it. |
1 |
Reg.OpenKey(cMyFileType + '\Shell\Open\Command', True); |
1 |
Reg.WriteString('', '"' + ExeName + '" "%1"'); |
1 |
Reg.CloseKey; |
1 |
// Finally, we want the Windows Explorer to realize we added |
1 |
// our file type by using the SHChangeNotify API. |
1 |
if DoUpdate then SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); |
1 |
finally |
1 |
Reg.Free; |
1 |
end; |
1 |
end; |
1 |
|
1 |
|
1 |
<b><u>Esempio : </u></b> |
1 |
<b> </b> |
1 |
All'interno della vostra applicazione allo stratup potete inserire il richiamo della procedura come segue : |
1 |
<b> </b> |
1 |
<b>RegisterFileType('.PJK','PJK','Project by CSD Revelli',Application.ExeName,0,True);</b> |