golang 怎么设置cmd窗口标题

编辑整理:
久良优品老秦
热度:
6072

go语言怎么设置cmd窗口标题便识别。

golang go语言怎么设置cmd窗口标题。582bf

windows下开发go,一般就直接编译成exe文件了。e0076e2

运行后的命令提示符窗口,有标题更方便识别。www.9lyp.com


131470de

调用方法:SetCmdTitle(“新标题”)abb


函数

87aa0b

func SetCmdTitle(title string) {www.9lyp.com

kernel32, _ := syscall.LoadLibrary(`kernel32.dll`)abb

sct, _ := syscall.GetProcAddress(kernel32, `SetConsoleTitleW`)www.9lyp.com

syscall.Syscall(sct, 1, uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))), 0, 0)e0076e2

syscall.FreeLibrary(kernel32)582bf

}1dad9df


syscall.StringToUTF16Ptr(title)www.9lyp.com

这句会提示已经过期,abb

改成:e0076e2

strUtf16,_ := syscall.UTF16PtrFromString(title)

87aa0b

syscall.Syscall(sct, 1, uintptr(unsafe.Pointer(strUtf16)), 0, 0)e0076e2



582bf


www.9lyp.com

87aa0b