Announcement

Collapse
No announcement yet.

Kann man das Desktop-Hintergrundbild verändern

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Kann man das Desktop-Hintergrundbild verändern

    Hallo

    ich will das Hintergrundbild vom Windows-desktop mit delphi automatisch ändern , hab schon gesucht aber nichts gefunden ...

    stefan

  • #2
    Hallo,

    das Hintergrundbild von Windows kann man naturlich mit Delphi verändern und zwar so:
    <PRE>
    procedure SetBackground(const AFilename: String);
    begin
    SystemParametersInfo(SPI_SETDESKWALLPAPER,
    0,
    pChar(AFilename),
    SPIF_SENDCHANGE OR SPIF_UPDATEINIFILE);
    End;
    </PRE>

    wobei man bei "AFilename" den Dateinamen angeben muss.

    Gruss Marku

    Comment


    • #3
      ich habs versucht klappt aber nich (weder unter XP,2000,98)
      ich weis nicht was der fehler is :

      --------------------------------------------------------------------

      procedure TForm1.FormActivate(Sender: TObject);

      var

      test : String;

      begin

      test := ExtractFilePath(ParamStr(0));

      test := test + 'alienmoon1024x768.jpg';

      SetBackground(test);

      Close;

      end;//procedure TForm1.FormActivate(Sender: TObject);

      procedure TForm1.SetBackground(const AFilename: String);

      begin

      SystemParametersInfo(SPI_SETDESKWALLPAPER,

      0,

      pChar(AFilename),

      SPIF_SENDCHANGE OR SPIF_UPDATEINIFILE);

      End;

      --------------------------------------------------------------------
      das es die Datei gibt , und sie im richtigen ordner is habe ich geprüft , das er alle befehle abarbeitet habe ich geprüft , selbst das die breite des Bildes mit der Auflösung übereistimmt hab ich geprüft ...

      als ich mal die hilfe zu "SystemParametersInfo" aufrufen wollte hab ich nichts gefunden (ich arbeite mit Delphi 7) ...

      PS: wenn bildgröße & Auflösung nicht übereintsimmen was macht er dann (Kacheln , Zentrieren , Strecken)???

      Comment


      • #4
        ich habs jetzt auch noch mal mit Delphi 6 versuch , bringt auch nicht

        Comment


        • #5
          <p>Hallo,<br>
          <br>
          SystemParameterinfo funktioniert nicht mit aktivierten ActiveDesktop zusammen. Folgendes Beispiel (#19661 aus dem Borland-FAQ) zeigt, wie es mit ActiveDesktop geht:
          <pre>
          uses
          ComObj, // For CreateComObject and Initialization/Finalization of COM
          ShlObj; // For IActiveDesktop
          { The CLASS ID for ActiveDesktop is not defined in
          ShlObj, while the IID is so we define it here. }
          const
          CLSID_ActiveDesktop: TGUID = '{75048700-EF1F-11D0-9888-006097DEACF9}';
          { Demonstrate getting the Wallpaper }
          procedure TForm1.Button1Click(Sender: TObject);
          var
          ActiveDesktop: IActiveDesktop;
          CurrentWallpaper: string;
          CurrentPattern: string;
          WallpaperOptions: TWallpaperOpt;
          tmpBuffer: PWideChar;
          begin
          // Create the ActiveDesktop COM Object
          ActiveDesktop := CreateComObject(CLSID_ActiveDesktop) as IActiveDesktop;
          // We now need to allocate some memory to get the current Wallpaper.
          // However, tmpBuffer is a PWideChar which means 2 bytes make
          // up one Char. In order to compenstate for the WideChar, we
          // allocate enough memory for MAX_PATH*2
          tmpBuffer := AllocMem(MAX_PATH*2);
          try
          ActiveDesktop.GetWallpaper(tmpBuffer, MAX_PATH*2, 0);
          CurrentWallpaper := tmpBuffer;
          finally
          FreeMem(tmpBuffer);
          end;
          if CurrentWallpaper <> '' then
          Label1.Caption := 'Current Wallpaper: ' + CurrentWallpaper
          else
          Label1.Caption := 'No Wallpaper set';
          // Now get the current Wallpaper options.
          // The second parameter is reserved and must be 0.
          WallpaperOptions.dwSize := SizeOf(WallpaperOptions);
          ActiveDesktop.GetWallpaperOptions(WallpaperOptions , 0);
          case WallpaperOptions.dwStyle of
          WPSTYLE_CENTER: Label2.Caption := 'Centered';
          WPSTYLE_TILE: Label2.Caption := 'Tiled';
          WPSTYLE_STRETCH: Label2.Caption := 'Stretched';
          WPSTYLE_MAX: Label2.Caption := 'Maxed';
          end;
          // Now get the desktop pattern.
          // The pattern is a string of decimals whose bit pattern
          // represents a picture. Each decimal represents the on/off state
          // of the 8 pixels in that row.
          tmpBuffer := AllocMem(256);
          try
          ActiveDesktop.GetPattern(tmpBuffer, 256, 0);
          CurrentPattern := tmpBuffer;
          finally
          FreeMem(tmpBuffer);
          end;
          if CurrentPattern <> '' then
          Label3.Caption := CurrentPattern
          else
          Label3.Caption := 'No Pattern set';
          end;
          { Demonstrate setting the wallpaper }
          procedure TForm1.Button2Click(Sender: TObject);
          var
          ActiveDesktop: IActiveDesktop;
          begin
          ActiveDesktop := CreateComObject(CLSID_ActiveDesktop)
          as IActiveDesktop;
          ActiveDesktop.SetWallpaper('c:\downloads\images\te st.bmp', 0);
          ActiveDesktop.ApplyChanges(AD_APPLY_ALL or AD_APPLY_FORCE);
          end;
          </pre>
          Gruß Thomas</p&gt

          Comment


          • #6
            ess klappt , huraa

            aber ...

            da das bild das als hintergrundbild dargestellt werden soll im gleichen verzeichnis liegt , hol ich mir den pfad über "ExtractFilePath(ParamStr(0))" , dass geht jedochn nur mit einer String Variable , und "ActiveDesktop.SetWallpaper" will unbedingt einen PWchar (PWideChar) haben ,

            kann man PWchar nach String konvertieren ???
            (
            "X : PWChar;
            Y : String;

            X := PWchar(Y);"
            habe ich schon probiert

            Comment


            • #7
              <p>Hallo,<br>
              <br>
              Delphi kennt Funktionen <b>StringToWideChar</b> und <b>WideCharToString</b> die dies können. Näheres dazu in der Delphi-Hilfe.<br>
              <br>
              Gruß Thomas</p&gt

              Comment

              Working...
              X