!SetWallpaper: Fixed that didn't work on Windows 7 with .png images.

This commit is contained in:
Birunthan Mohanathas 2012-03-08 05:21:11 +00:00
parent c53f8a87cc
commit 3905a71af3

View File

@ -1154,7 +1154,22 @@ void CSystem::SetClipboardText(const std::wstring& text)
*/ */
void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& style) void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& style)
{ {
auto setWallpaperStyle = [&]() if (!wallpaper.empty())
{
if (_waccess(wallpaper.c_str(), 0) == -1)
{
LogWithArgs(LOG_ERROR, L"!SetWallpaper: Unable to read file: %s", wallpaper.c_str());
return;
}
Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str());
if (bitmap && bitmap->GetLastStatus() == Ok)
{
std::wstring file = Rainmeter->GetSettingsPath();
file += L"Wallpaper.bmp";
const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } };
if (bitmap->Save(file.c_str(), &bmpClsid) == Ok)
{ {
if (!style.empty()) if (!style.empty())
{ {
@ -1203,39 +1218,11 @@ void CSystem::SetWallpaper(const std::wstring& wallpaper, const std::wstring& st
RegCloseKey(hKey); RegCloseKey(hKey);
} }
} }
};
if (!wallpaper.empty())
{
if (_waccess(wallpaper.c_str(), 0) == -1)
{
LogWithArgs(LOG_ERROR, L"!SetWallpaper: Unable to read file: %s", wallpaper.c_str());
return;
}
if (GetOSPlatform() < OSPLATFORM_7)
{
// Gotta convert to .bmp for pre-7
Bitmap* bitmap = Bitmap::FromFile(wallpaper.c_str());
if (bitmap && bitmap->GetLastStatus() == Ok)
{
std::wstring file = Rainmeter->GetSettingsPath();
file += L"Wallpaper.bmp";
const CLSID bmpClsid = { 0x557cf400, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x0, 0x0, 0xf8, 0x1e, 0xf3, 0x2e } };
if (bitmap->Save(file.c_str(), &bmpClsid) == Ok)
{
setWallpaperStyle();
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)file.c_str(), SPIF_UPDATEINIFILE); SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)file.c_str(), SPIF_UPDATEINIFILE);
} }
} }
} }
else
{
setWallpaperStyle();
SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (void*)wallpaper.c_str(), SPIF_UPDATEINIFILE);
}
}
} }
/* /*