I am trying to associate a specific filetype (eg .doc) to my application. I am currently using IApplicationActivationManager
to do this as IApplicationAssociationRegistration::SetAppAsDefault
method no longer works for Win 8 and above and so is editing the registry due to the UserChoice\Hash
value.
This association will be triggered when the user clicks on my app's settings then choosing "Set as default". So far, IApplicationActivationManager
works for me as it mimics one way on how Windows 10 sets a default file type for an application through "Settings -> System -> Default apps -> Choose default apps by file type" when the user chooses to do so.
Is there is a way to focus on the file type programmatically upon opening "...-> Choose default apps by file type"? Or better yet, launch programmatically "...-> Choose default apps by file type -> Choose an app" dialog for that specific file type?
Sample code:
procedure TForm1.Btn2Click(Sender: TObject);
const
OPENSETTINGS = 'Windows.ImmersiveControlPanel_cw5n1h2txyewy!microsoft.windows.immersivecontrolpanel';
PAGESETTINGSBYFILETYPE = 'page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView';
var
pAAR: IApplicationActivationManager;
pid: PDWORD;
Res: HRESULT;
begin
Res := CoCreateInstance(CLSID_ApplicationActivationManager, nil,
CLSCTX_LOCAL_SERVER, IApplicationActivationManager, pAAR);
if Succeeded(FRes)
pAAR.ActivateApplication(OPENSETTINGS, PAGESETTINGSBYFILETYPE, AO_NONE, pid)
else
ShowMessage('Failed!');
end;
For example, can the command
page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView
be extended to scroll to and select a specific file type, something like
page=SettingsPageAppsDefaults&target=SettingsPageAppsDefaultsFileExtensionView&filetype=.doc'
? Or some other solution to accomplish the same thing?