Go进程改标题
2021-10-14 本文已影响0人
游学者夏纳
朴实无华。(置顶的文章被jianshu删了,笑死)
import (
"syscall"
"unsafe"
)
func SetConsoleTitleW(title string) {
kernel32, err := syscall.LoadLibrary(`kernel32.dll`)
if err != nil {
return
}
if sct, err := syscall.GetProcAddress(kernel32, `SetConsoleTitleW`); err == nil {
if pu, err := syscall.UTF16PtrFromString(title); err == nil {
_, _, _ = syscall.Syscall(sct, 1, uintptr(unsafe.Pointer(pu)), 0, 0)
}
}
_ = syscall.FreeLibrary(kernel32)
}