|  | 
| 
 复制代码#include <windows.h>
#include <string>
// 修改Windows桌面壁纸的函数
bool setWallpaper(const std::wstring& imagePath) {
    // 确保图片路径存在
    if (!std::filesystem::exists(imagePath)) {
        return false; // 图片文件不存在
    }
    // 调用SystemParametersInfo函数设置壁纸
    int result = SystemParametersInfo(
        SPI_SETDESKWALLPAPER, // 功能代码,用于设置桌面壁纸
        0,                    // 不使用此参数(需为0)
        imagePath.c_str(),     // 壁纸图片文件路径
        SPIF_UPDATEINIFILE | SPIF_SENDWININICHANGE); // 更新INI文件并发送变化通知
    // 检查操作是否成功
    return result != 0;
}
int main() {
    std::wstring imagePath = L"C:\\path\\to\\your\\image.jpg"; // 请替换为实际图片路径
    if (setWallpaper(imagePath)) {
        std::cout << "壁纸设置成功!" << std::endl;
    } else {
        std::cout << "设置壁纸时发生错误。" << std::endl;
    }
    return 0;
}
 
 
 
 
 | 
 |