使用 IActiveDesktop 接口获取设置桌面背景图片

#ifndef AD_GETWP_LAST_APPLIED #define AD_GETWP_LAST_APPLIED 0x00000002 #endif // BOOL GetWallPaper(CStringW &szFile, BOOL &dwStyle) { BOOL bRet = 0; IActiveDesktop *pActiveDesktop; HRESULT hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop); if(hr == S_OK) { WALLPAPEROPT WallpaperOpt = { sizeof(WALLPAPEROPT), 0 }; VERIFY(pActiveDesktop->GetWallpaperOptions(&WallpaperOpt, 0) == S_OK); dwStyle = WallpaperOpt.dwStyle; WCHAR szPathFile[MAX_PATH + 1] = {0}; VERIFY(pActiveDesktop->GetWallpaper(szPathFile, MAX_PATH, AD_GETWP_LAST_APPLIED) == S_OK); szFile = szPathFile; pActiveDesktop->Release(); bRet = TRUE; } return bRet; } BOOL SetWallPaper(LPCWSTR szFile, DWORD dwStyle) { BOOL bRet = 0; IActiveDesktop *pActiveDesktop; HRESULT hr = CoCreateInstance(CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER, IID_IActiveDesktop, (void**)&pActiveDesktop); if(hr == S_OK) { WALLPAPEROPT WallpaperOpt = { sizeof(WALLPAPEROPT), dwStyle }; VERIFY(pActiveDesktop->SetWallpaperOptions(&WallpaperOpt, 0) == S_OK); VERIFY(pActiveDesktop->SetWallpaper(szFile, 0) == S_OK); VERIFY(pActiveDesktop->ApplyChanges(AD_APPLY_ALL | AD_APPLY_FORCE) == S_OK); pActiveDesktop->Release(); bRet = TRUE; } return bRet; }

你可能感兴趣的:(server,null,Path)