您好,欢迎来到二三四教育网。
搜索
您的当前位置:首页使用代码修改Windows系统壁纸的方法

使用代码修改Windows系统壁纸的方法

来源:二三四教育网

另外,所有方法均需要图片为bmp格式。否则需要先转换得到bmp格式的图片。

Python

import win32gui

def setWallpaper(imgPath):
    win32gui.SystemParametersInfo(20, imgPath, 3)

Go

import (
  "syscall"
  "unsafe"
  "fmt"
)

func setWallPaper(imgPath string) {
    dll := syscall.NewLazyDLL("user32.dll")
    proc := dll.NewProc("SystemParametersInfoW")
    ret, _, _ := proc.Call(20, 1,
        uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(imgPath))),
            0x1 | 0x2)
    fmt.Print(ret)
}

Node

C++

在微软官方网站给出的代码基础上修改:

#include <windows.h>
#include <iostream>
#pragma comment(lib, "user32.lib")    

int main()  
{     
    BOOL fResult;
    UINT* bmpPath = (UINT*)"D:\\Pictures\\wp.bmp"; 
    
    fResult = SystemParametersInfo(SPI_SETDESKWALLPAPER,
                                   1,
                                   bmpPath,
                                   SPIF_UPDATEINIFILE);
    std::cout << fResult;
    return 0;
}

C#

// 部分
[DllImport("user32.dll", EntryPoint = "SystemParametersInfoA")]
static extern Int32 SystemParametersInfo(Int32 uAction, Int32 uParam, string lpvparam, Int32 fuwinIni);

void fucntion SetWallpaper(imgPath) {
  int nResult;
  nResult = SystemParametersInfo(20, 1, bmpPath, 0x1 | 0x2);
}

Copyright © 2019- how234.cn 版权所有 赣ICP备2023008801号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务