LoginSignup
2
1

More than 5 years have passed since last update.

[Windows]Goでデスクトップの壁紙を変更する

Posted at

目的

Goを使ってWindows端末のデスクトップ壁紙を変更してみます。

DLLの読み込みと実行をGoで試してみたかったのでやってみました。

壁紙の変更方法

Windowsの場合、壁紙変更はuser32.dllSystemParametersInfoを呼び出すことで変更できます。また、Goはsyscall.LoadDLLでDLLをロードし、DLL.FindProcでDLL内のプロシージャを取得、Proc.Callで実行できます。

package main

import (
    "syscall"
    "unsafe"
)

func main() {
    user32, _ := syscall.LoadDLL("user32.dll")
    defer user32.Release()
    systemParametersInfoW, _ := user32.FindProc("SystemParametersInfoW")
    path, _ := syscall.UTF16PtrFromString(`C:\Users\v\Pictures\example.png`)
    systemParametersInfoW.Call(0x0014, 0, uintptr(unsafe.Pointer(path)), 0x02)
}

参考

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1