Einzelnen Beitrag anzeigen

Benutzerbild von KodeZwerg
KodeZwerg

Registriert seit: 1. Feb 2018
3.685 Beiträge
 
Delphi 11 Alexandria
 
#11

AW: Wallpaper per Monitor?

  Alt 10. Feb 2023, 13:49
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;
Gruß vom KodeZwerg

Geändert von KodeZwerg (10. Feb 2023 um 14:41 Uhr)
  Mit Zitat antworten Zitat