#include <Windows.h> #include <string> #include "Shobjidl.h" int main() { std::wstring x = L"C:\Users\strives\Desktop\ScreenShot\panda.png"; HRESULT ad; CoInitialize(NULL); IDesktopWallpaper* p; if (SUCCEEDED(CoCreateInstance(__uuidof(DesktopWallpaper), 0, CLSCTX_LOCAL_SERVER, __uuidof(IDesktopWallpaper), (void**)&p))) { ad = p->SetWallpaper(NULL, x.c_str()); p->Release(); } CoUninitialize(); return 0; }
初始化IDesktopWallpaper对象,调用SetWallpaper方法