Desktop Window
-
Ich möchte gerne das Desktophintergrundbild ändern. In der MSDN bin ich auch fündig geworden, kann das was dort steht, nicht umsetzen.
Einerseits müsste ich doch die Adresse des Hintergrundbildes angeben, nicht nur den Namen... (Wäre meine Logik, leider funktioniert aber beides nicht.)
Hat mir jemand vielleicht einen Codeauszug?Aus der MSDN:
When you start the system, it automatically creates the desktop window. The desktop window is a system-defined window that paints the background of the screen and serves as the base for all windows displayed by all applications.
The desktop window uses a bitmap to paint the background of the screen. The pattern created by the bitmap is called the desktop wallpaper. By default, the desktop window uses the bitmap from a .BMP file specified in the registry as the desktop wallpaper.
The GetDesktopWindow function returns a handle to the desktop window.
A system configuration application, such as a Control Panel applet, changes the desktop wallpaper by using the SystemParametersInfo function with the wAction parameter set to SPI_SETDESKWALLPAPER and the lpvParam parameter specifying a bitmap filename. SystemParametersInfo then loads the bitmap from the specified file, uses the bitmap to paint the background of the screen, and enters the new filename in the registry
-
A system configuration application, such as a Control Panel applet, changes the desktop wallpaper by using the SystemParametersInfo function with the wAction parameter set to SPI_SETDESKWALLPAPER and the lpvParam parameter specifying a bitmap filename.
Welchen Teil hast Du nicht verstanden?
Gib doch als lpvParam einfach "C:\\Windows\\MeinBitmap.bmp" an... Wo ist das Problem???
-
Es wird nichts geändert. Weder in der Registry habe ich etwas gefunden, noch nützt es etwas, wenn ich die F5- Taste drücke....
TCHAR szBuffer[100]; sprintf(szBuffer,"D:\\Eigene Dateien\\Eigene Bilder\\%s",wfd.cFileName); SystemParametersInfo(SPI_SETDESKWALLPAPER,0,szBuffer,SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
-
-
Bei mir funktioniert es immernoch nicht.....
Könnte jemand vieleicht das ganze bei sich ausprobieren?
Thomas[code type="C++" tabs="4"]
#include <windows.h>
#include <stdio.h>
#include <time.h>int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
PSTR szCmdLine, int iCmdShow)
{
int AnzahlBilder=0;
HANDLE fHandle;
WIN32_FIND_DATA wfd;
TCHAR szBuffer[100];
time_t t;
HKEY hKey;// Erste Datei im Verzeichnis "c:\windows\desktop\" holen:
// aufgrund von "alten Zeiten" ist das erste immer ein "."
// kann also ignoriert werden.
fHandle=FindFirstFile("d:\\eigene dateien\\eigene Bilder\*",&wfd);// Ergebnis Nummer 2 ist auch uninteressant (ist ".."):
FindNextFile(fHandle,&wfd);// Die Anzahl der Bilder ermitteln
while (FindNextFile(fHandle,&wfd))
{
AnzahlBilder++;
}
FindClose(fHandle);// Eine Zufallszahl bestimmen
time(&t);
srand((unsigned int)t);
AnzahlBilder = rand() % AnzahlBilder + 2;// Entsprechendes Bild in szBuffer speichern
fHandle=FindFirstFile("D:\\Eigene Dateien\\Eigene Bilder\*",&wfd);for (int i = 0; i<AnzahlBilder; i++)
{
FindNextFile(fHandle,&wfd);
}FindClose(fHandle);
sprintf(szBuffer,"D:\\Eigene Dateien\\Eigene Bilder\%s",wfd.cFileName);
// Pfad in die Registry eintragen
RegOpenKeyEx(HKEY_CURRENT_USER,"Control Panel\\Desktop",0,KEY_ALL_ACCESS,&hKey);
RegSetValueEx(hKey,"Wallpaper",0,REG_SZ,(LPBYTE)szBuffer,strlen(szBuffer));
RegCloseKey(hKey);SystemParametersInfo(SPI_SETDESKWALLPAPER,0,0,SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE);
return 0;
}
-
Wenn ich den Fehler mit GetLastError() abfange, bekomme ich den Wert 18 zurück. Laut MSDN:
18 There are no more files. ERROR_NO_MORE_FILESDer Fehler taucht dann auf, wenn ich die Anzahl der Bilder ermittle....