JumpListTest (Delphi)

Description

This example uses the RegisterFileExtension function to register your executable on the system as a file handler. The RegisterFileExtensionsToUser function works for a list of instances.
As a result, you can have Frequent and Recent Lists available for your app.

Code

unituRegisterFileType;interfaceusesSystem.Win.Registry,System.Generics.Collections;typeTFileRegisterInformation=recordExtension:string;FileTypeDescription:string;DefIconPath:string;OpenCommand:string;Exename:string;end;functionRegisterFileExtensionsToUser(aFileExtList:TList<TFileRegisterInformation>):boolean;functionRegisterFileExtension(FileInfo:TFileRegisterInformation):Boolean;implementationusesWinapi.ShlObj,Winapi.Windows;functionRegisterFileExtension(FileInfo:TFileRegisterInformation):Boolean;constSOFT_CLASSES='\Software\Classes\';// do not localizevarLReg:TRegistry;buffer:Pointer;beginResult:=False;LReg:=TRegistry.Create;tryLReg.RootKey:=HKEY_CURRENT_USER;ifLReg.OpenKey(SOFT_CLASSES+FileInfo.Extension+'\OpenWithProgids',true)thenLReg.WriteBinaryData(FileInfo.Exename,buffer,0);ifLReg.OpenKey(SOFT_CLASSES+FileInfo.Exename,true)thenLReg.WriteString('',FileInfo.FileTypeDescription);ifLReg.OpenKey(SOFT_CLASSES+FileInfo.Exename+'\DefaultIcon',true)thenLReg.WriteString('',FileInfo.DefIconPath);ifLReg.OpenKey(SOFT_CLASSES+FileInfo.Exename+'\shell\open\command',true)thenLReg.WriteString('',FileInfo.OpenCommand);Result:=True;finallyLReg.Free;end;SHChangeNotify(SHCNE_ASSOCCHANGED,SHCNF_IDLIST,nil,nil);end;functionRegisterFileExtensionsToUser(aFileExtList:TList<TFileRegisterInformation>):Boolean;constSOFT_CLASSES='\Software\Classes\';// do not localizevaraFileRegInfo:TFileRegisterInformation;beginResult:=False;foraFileRegInfoinaFileExtListdobeginResult:=RegisterFileExtension(aFileRegInfo);ifnotResultthenBreak;end;end;end.