Go语言:设置命令提示符(CMD)标题

2023-11-29 09:40:26 浏览数 (1)

代码语言: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)
}
go

0 人点赞