在这行的前面一行插入 include #include <wininet.h>
在需要调用的CPP文件中:
#include <atlbase.h>
#include <shlguid.h>
#include <shlobj.h>
#include <comdef.h>
::CoInitialize(NULL); IActiveDesktop *pDesk=NULL; HRESULT hr = ::CoCreateInstance(CLSID_ActiveDesktop,NULL,CLSCTX_INPROC_SERVER, IID_IActiveDesktop,(LPVOID *)&pDesk); ASSERT(SUCCEEDED(hr)); WCHAR path[MAX_PATH]; hr=pDesk->GetWallpaper(path,sizeof(path),0); //取得壁纸文件名 //设置壁纸文件是: SetWallpaper(LPCWSTR pwszWallpaper,DWORD dwReserved); ASSERT(SUCCEEDED(hr)); CString s(path); AfxMessageBox(s); if(pDesk) pDesk->Release(); ::CoUninitialize();