I have created a simple application using Delphi 10.2 Tokyo (using FireMonkey) that displays images and allows you to set the desktop wallpaper for a selected image. The main code that sets the desktop wallpaper is:
class procedure TUtilityWin.SetWallpaper(AFileName: String);
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pChar(AFileName), (SPIF_UPDATEINIFILE OR SPIF_SENDWININICHANGE));
While this works great when the application runs on the desktop (as a standalone install), it fails when run as an APPX (during the certification process) of submitting to the Windows 10 App Store. When setting the wallpaper as an APPX, the result is a black screen background instead of the selected image.
I thought that this was due to the APPX running in a constrained mode with access only to a virtual registry (and not the actual registry). So I changed the call to this:
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pChar(AFileName), 0);
This also works when run as a standalone application on the desktop. But even removing the parameter SPIF_UPDATEINIFILE does not get the app to work as an APPX package deployment – it still does not set the wallpaper and results in a black screen.
Would be interested in any guidance from this community about how I can set the desktop wallpaper and have it work even when packaged and deployed as an APPX. Thanks in advance!
Addendum: I am going off this documentation (excerpt below):
If a system parameter is being set, specifies whether the user profile
is to be updated, and if so, whether the WM_SETTINGCHANGE message is
to be broadcast to all top-level windows to notify them of the change.
This parameter can be zero if you do not want to update the user
profile or broadcast the WM_SETTINGCHANGE message…
Based on feedback from @Victoria and @DaveNottage, I took a stab at implementing WinRT calls as follows:
Uses WinAPI.WinRT, WinApi.SystemRT, WinAPI.Storage, WinApi.Foundation.Types;
procedure TForm1.Button1Click(Sender: TObject);
imgfname: String = ‘C:\Users\rohit\Pictures\Camera Roll\WIN_20170302_12_12_33_Pro.jpg’;
if TUserProfile_UserProfilePersonalizationSettings.IsSupported then
isf_StorageFile.Completed:= AsyncOperationCompletedHandler_1__IStorageFile (
procedure (sf: IAsyncOperation_1__IStorageFile; status: AsyncStatus)
if status=AsyncStatus.Completed then
Unfortunately this does not work and gives an error: No such interface supported. Would appreciate it if someone could look over this and let me know what I am doing wrong…