Initial GoWallpaper implementation
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
//go:build windows
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
const instanceMutexName = `Local\GoWallpaper-4F831CA6-6890-4D95-91A3-A819D7F29718`
|
||||
|
||||
func acquireSingleInstance() (windows.Handle, bool, error) {
|
||||
name, err := windows.UTF16PtrFromString(instanceMutexName)
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
handle, err := windows.CreateMutex(nil, false, name)
|
||||
if errors.Is(err, windows.ERROR_ALREADY_EXISTS) {
|
||||
return handle, true, nil
|
||||
}
|
||||
if err != nil {
|
||||
return 0, false, err
|
||||
}
|
||||
return handle, false, nil
|
||||
}
|
||||
|
||||
func showNativeMessage(title, message string) {
|
||||
titlePtr, _ := windows.UTF16PtrFromString(title)
|
||||
messagePtr, _ := windows.UTF16PtrFromString(message)
|
||||
procMessageBoxW := user32.NewProc("MessageBoxW")
|
||||
procMessageBoxW.Call(
|
||||
0,
|
||||
uintptr(unsafe.Pointer(messagePtr)),
|
||||
uintptr(unsafe.Pointer(titlePtr)),
|
||||
0x00000040,
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user