SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, "C:\\xxx.bmp", SPIF_SENDWININICHANGE| SPIF_UPDATEINIFILE); |
#include <afxwin.h> #include <wininet.h> //添加这个。注意顺序,顺序乱了也编译不过 #include <afxext.h> ... |
#include <shlobj.h> |
BOOL CTest6Dlg::SetWallPaper(CString strPath) { HRESULT hr; IActiveDesktop* pIAD; hr = CoCreateInstance( CLSID_ActiveDesktop, NULL, CLSCTX_INPROC_SERVER,IID_IActiveDesktop, (void**)&pIAD); if ( !SUCCEEDED(hr) ) return FALSE; // 设置墙纸前先打开活动桌面开关 COMPONENTSOPT co = {0}; co.dwSize = sizeof(COMPONENTSOPT); co.fEnableComponents = TRUE; co.fActiveDesktop = TRUE; hr = pIAD->SetDesktopItemOptions(&co, 0); if ( !SUCCEEDED(hr) ) return FALSE; //做以下宽字符的转换是因为SetWallpaper的参数是用的LPCWSTR WCHAR wszPath[MAX_PATH]; LPTSTR lpStr = strPath.GetBuffer(strPath.GetLength()); MultiByteToWideChar(CP_ACP, 0, lpStr, -1, wszPath, MAX_PATH); strPath.ReleaseBuffer(); // 设置墙纸 hr = pIAD->SetWallpaper(wszPath, 0); if ( !SUCCEEDED(hr) ) return FALSE; // 设置墙纸风格 WALLPAPEROPT wp = {0}; wp.dwSize = sizeof(WALLPAPEROPT); wp.dwStyle |= WPSTYLE_CENTER; hr = pIAD->SetWallpaperOptions(&wp, 0); if ( !SUCCEEDED(hr) ) return FALSE; // 应用改变 hr = pIAD->ApplyChanges(AD_APPLY_ALL); if ( !SUCCEEDED(hr) ) return FALSE; // 最后释放接口,不要忘了 pIAD->Release(); } |
欢迎访问最专业的网吧论坛,无盘论坛,网吧经营,网咖管理,网吧专业论坛
https://bbs.txwb.com
关注天下网吧微信/下载天下网吧APP/天下网吧小程序,一起来超精彩
|
本文来源:vczx 作者:佚名