代码语言:javascript复制
package main
import (
"syscall"
"unsafe"
)
func main() {
setTitle(`你好世界!`)
}
func setTitle(title string) {
kernel32, _ := syscall.LoadLibrary(`kernel32.dll`)
sct, _ := syscall.GetProcAddress(kernel32, `SetConsoleTitleW`)
syscall.Syscall(sct, 1, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), 0, 0)
syscall.FreeLibrary(kernel32)
}