首页 > 技术文章 > 用IDesktopWallpaper接口设置png壁纸

strive-sun 2019-11-20 09:56 原文

#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方法

推荐阅读