Wie lautet das Code-Snippet als Delphi-Code?
Ich würde es so umsetzen:
Delphi-Quellcode:
function SetWallpaperAPI(const AMonitor: Integer; const AFilename: string): Boolean;
var
LIWallpaper : IDesktopWallpaper;
LMonitorID,
LWallpaperFile : PWideChar;
LCount : DWORD;
begin
Result := False;
if (AMonitor < 0) then
Exit;
if not FileExists(AFilename) then
Exit;
LWallpaperFile := PWideChar(AFilename);
LIWallpaper := CoDesktopWallpaper.Create;
try
OleCheck(LIWallpaper.GetMonitorDevicePathCount(LCount));
if (AMonitor >= LCount) then
Exit;
OleCheck(LIWallpaper.GetMonitorDevicePathAt(AMonitor, LMonitorID));
OleCheck(LIWallpaper.SetWallpaper(LMonitorID, LWallpaperFile));
finally
Result := True;
end;
end;