<p>Trying to change my desktops wallpaper i wrote this code using what i could understand from the API, But the wallpaper just turns black...
package main</p>
<pre><code>import (
"fmt"
"syscall"
"time"
"unsafe"
)
var (
user32 = syscall.NewLazyDLL("user32.dll") //user32.dll
systemParametersInfo = user32.NewProc("SystemParametersInfoA")
)
func main() {
ImageLocA := `C:\Users\satur\Desktop\a.jpg`
ImageLocB := `C:\Users\satur\Desktop\b.jpg`
fmt.Println("Setting BG to: " + ImageLocA)
ret, _, _ := systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocA))), 0x01)
fmt.Println(ret)
time.Sleep(5 * time.Second)
fmt.Println("Setting BG to: " + ImageLocB)
ret, _, _ = systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocB))), 0x01)
fmt.Println(ret)
}
</code></pre>
<hr/>**评论:**<br/><br/>SaturnsVoid: <pre><p>I figured it out, I was using SystemParametersInfoA when i needed SystemParametersInfoW!</p>
<p>Info: <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx" rel="nofollow">https://msdn.microsoft.com/en-us/library/windows/desktop/ms724947(v=vs.85).aspx</a></p>
<p>Fixed Working Code:
package main</p>
<pre><code>import (
"fmt"
"syscall"
"time"
"unsafe"
)
var (
user32 = syscall.NewLazyDLL("user32.dll") //user32.dll
systemParametersInfo = user32.NewProc("SystemParametersInfoW")
)
func main() {
ImageLocA := `C:\Users\satur\Desktop\a.jpg`
ImageLocB := `C:\Users\satur\Desktop\b.jpg`
fmt.Println("Setting BG to: " + ImageLocA)
ret, _, _ := systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocA))), 2)
fmt.Println(ret)
time.Sleep(5 * time.Second)
fmt.Println("Setting BG to: " + ImageLocB)
ret, _, _ = systemParametersInfo.Call(20, 0, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(ImageLocB))), 2)
fmt.Println(ret)
}
</code></pre></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
0 回复
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传