bool ImageHandler::GetDesktopImageData(ImageData& imageData) { CRegKey keyColors; if (keyColors.Open(HKEY_CURRENT_USER, L"Control Panel\\Colors", KEY_READ) != ERROR_SUCCESS) return false; CString strBackground; DWORD dwDataSize = 32; if (keyColors.QueryStringValue(L"Background", strBackground.GetBuffer(dwDataSize), &dwDataSize) != ERROR_SUCCESS) { strBackground.ReleaseBuffer(); return false; } strBackground.ReleaseBuffer(); wstringstream streamBk(wstring(strBackground.operator LPCTSTR())); DWORD r = 0; DWORD g = 0; DWORD b = 0; streamBk >> r; streamBk >> g; streamBk >> b; CRegKey keyDesktop; if (keyDesktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop", KEY_READ) != ERROR_SUCCESS) return false; DWORD dwChars = 0; CString strWallpaperFile; CString strWallpaperStyle; CString strWallpaperTile; dwChars = 32; keyDesktop.QueryStringValue(L"WallpaperStyle", strWallpaperStyle.GetBuffer(dwChars), &dwChars); dwChars = 32; keyDesktop.QueryStringValue(L"TileWallpaper", strWallpaperTile.GetBuffer(dwChars), &dwChars); dwChars = MAX_PATH; keyDesktop.QueryStringValue(L"Wallpaper", strWallpaperFile.GetBuffer(dwChars), &dwChars); strWallpaperStyle.ReleaseBuffer(); strWallpaperFile.ReleaseBuffer(); strWallpaperTile.ReleaseBuffer(); // set background data imageData.strFilename = strWallpaperFile; imageData.bRelative = true; imageData.bExtend = false; imageData.crBackground = RGB(static_cast<BYTE>(r), static_cast<BYTE>(g), static_cast<BYTE>(b)); if (strWallpaperTile == L"1") { imageData.imagePosition= imagePositionTile; } else { if (strWallpaperStyle == L"0") { imageData.imagePosition= imagePositionCenter; } else if (strWallpaperStyle == L"6") { imageData.imagePosition= imagePositionFit; } else if (strWallpaperStyle == L"10") { imageData.imagePosition= imagePositionFill; } else if (strWallpaperStyle == L"22") { imageData.imagePosition= imagePositionFill; imageData.bExtend = true; } else { imageData.imagePosition= imagePositionStretch; } } return true; }
bool ImageHandler::GetDesktopImageData(ImageData& imageData) { CRegKey keyColors; if (keyColors.Open(HKEY_CURRENT_USER, L"Control Panel\\Colors", KEY_READ) != ERROR_SUCCESS) return false; CString strBackground; DWORD dwDataSize = 32; if (keyColors.QueryStringValue(L"Background", strBackground.GetBuffer(dwDataSize), &dwDataSize) != ERROR_SUCCESS) { strBackground.ReleaseBuffer(); return false; } strBackground.ReleaseBuffer(); wstringstream streamBk(wstring(strBackground.operator LPCTSTR())); DWORD r = 0; DWORD g = 0; DWORD b = 0; streamBk >> r; streamBk >> g; streamBk >> b; CRegKey keyDesktop; if (keyDesktop.Open(HKEY_CURRENT_USER, L"Control Panel\\Desktop", KEY_READ) != ERROR_SUCCESS) return false; DWORD dwChars = 0; CString strWallpaperFile; CString strWallpaperStyle; CString strWallpaperTile; dwChars = 32; keyDesktop.QueryStringValue(L"WallpaperStyle", strWallpaperStyle.GetBuffer(dwChars), &dwChars); dwChars = 32; keyDesktop.QueryStringValue(L"TileWallpaper", strWallpaperTile.GetBuffer(dwChars), &dwChars); dwChars = MAX_PATH; keyDesktop.QueryStringValue(L"Wallpaper", strWallpaperFile.GetBuffer(dwChars), &dwChars); strWallpaperStyle.ReleaseBuffer(); strWallpaperFile.ReleaseBuffer(); strWallpaperTile.ReleaseBuffer(); // set background data imageData.strFilename = strWallpaperFile; imageData.bRelative = true; imageData.bExtend = false; imageData.crBackground = RGB(static_cast<BYTE>(r), static_cast<BYTE>(g), static_cast<BYTE>(b)); if (strWallpaperTile == L"1") { imageData.imagePosition= imagePositionTile; } else { if (strWallpaperStyle == L"0") { imageData.imagePosition= imagePositionCenter; } else if (strWallpaperStyle == L"6") { imageData.imagePosition= imagePositionFit; } else if (strWallpaperStyle == L"10") { imageData.imagePosition= imagePositionFill; } else if (strWallpaperStyle == L"22") { imageData.imagePosition= imagePositionFill; imageData.bExtend = true; } else { imageData.imagePosition= imagePositionStretch; } } #if _WIN32_WINNT >= 0x0602 if( ImageHandler::IsWin8() ) { CComPtr<IDesktopWallpaper> desktopWallpaper; HRESULT hr = desktopWallpaper.CoCreateInstance(CLSID_DesktopWallpaper, nullptr, CLSCTX_ALL); if( SUCCEEDED(hr) ) { CComHeapPtr<wchar_t> spszWallpaper; hr = desktopWallpaper->GetWallpaper(NULL, &spszWallpaper); if( hr == S_OK ) imageData.bExtend = true; } } #endif return true; }