From 6af1813fda9a0e8d8ffe965cbc382f6f582dcd5c Mon Sep 17 00:00:00 2001 From: Katayama Hirofumi MZ Date: Mon, 18 Mar 2024 07:32:47 +0900 Subject: [PATCH] [MSPAINT] Support JPEG/PNG/GIF/TIFF wallpapers (#6632) Improve usability. JIRA issue: CORE-19485 - Enable the menu items to set the wallpapars. - Save the current bitmap as file Wallpaper1.bmp in CSIDL_LOCAL_APPDATA folder. - Support JPEG/PNG/GIF/TIFF files in RegistrySettings::SetWallpaper. --- base/applications/mspaint/main.cpp | 14 ------------- base/applications/mspaint/registry.cpp | 27 ++++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/base/applications/mspaint/main.cpp b/base/applications/mspaint/main.cpp index 6d9535842d7..3b6aa307810 100644 --- a/base/applications/mspaint/main.cpp +++ b/base/applications/mspaint/main.cpp @@ -642,20 +642,6 @@ LRESULT CMainWindow::OnClose(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL& bHan void CMainWindow::ProcessFileMenu(HMENU hPopupMenu) { - LPCWSTR dotext = PathFindExtensionW(g_szFileName); - BOOL isBMP = FALSE; - if (_wcsicmp(dotext, L".bmp") == 0 || - _wcsicmp(dotext, L".dib") == 0 || - _wcsicmp(dotext, L".rle") == 0) - { - isBMP = TRUE; - } - - UINT uWallpaperEnabled = ENABLED_IF(g_isAFile && isBMP && g_fileSize > 0); - ::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERPLANE, uWallpaperEnabled); - ::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERCENTERED, uWallpaperEnabled); - ::EnableMenuItem(hPopupMenu, IDM_FILEASWALLPAPERSTRETCHED, uWallpaperEnabled); - for (INT iItem = 0; iItem < MAX_RECENT_FILES; ++iItem) RemoveMenu(hPopupMenu, IDM_FILE1 + iItem, MF_BYCOMMAND); diff --git a/base/applications/mspaint/registry.cpp b/base/applications/mspaint/registry.cpp index 6302555c41b..46d45a8e101 100644 --- a/base/applications/mspaint/registry.cpp +++ b/base/applications/mspaint/registry.cpp @@ -38,16 +38,39 @@ static void ReadString(CRegKey &key, LPCWSTR lpName, CStringW &strValue, LPCWSTR void RegistrySettings::SetWallpaper(LPCWSTR szFileName, RegistrySettings::WallpaperStyle style) { + // Build the local path to the converted cached BMP wallpaper + HRESULT hr; + WCHAR szWallpaper[MAX_PATH]; + hr = SHGetFolderPathW(NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, 0, szWallpaper); + if (FAILED(hr)) + return; + hr = StringCchCatW(szWallpaper, _countof(szWallpaper), TEXT("\\Wallpaper1.bmp")); + if (FAILED(hr)) + return; + + // Save the converted wallpaper BMP + CImageDx img; + HBITMAP hbmLocked = imageModel.LockBitmap(); + img.Attach(hbmLocked); + hr = img.SaveDx(szWallpaper); + img.Detach(); + imageModel.UnlockBitmap(hbmLocked); + if (FAILED(hr)) + return; + + // Write the wallpaper settings to the registry CRegKey desktop; if (desktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop") == ERROR_SUCCESS) { desktop.SetStringValue(L"Wallpaper", szFileName); - desktop.SetStringValue(L"WallpaperStyle", (style == RegistrySettings::STRETCHED) ? L"2" : L"0"); desktop.SetStringValue(L"TileWallpaper", (style == RegistrySettings::TILED) ? L"1" : L"0"); + desktop.SetStringValue(L"ConvertedWallpaper", szWallpaper); + desktop.SetStringValue(L"OriginalWallpaper", szFileName); } - SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, (PVOID) szFileName, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); + // Set the desktop wallpaper + SystemParametersInfoW(SPI_SETDESKWALLPAPER, 0, szWallpaper, SPIF_UPDATEINIFILE | SPIF_SENDCHANGE); } void RegistrySettings::LoadPresets(INT nCmdShow)