package main
import (
"flag"
"syscall"
)
func main() {
defer func() {return }()
cc := flag.Int("i", 2, "Type: Int!")
flag.Parse()
count := int(-11)
objDll := syscall.NewLazyDLL("kernel32.dll")
colorHandle := objDll.NewProc("GetStdHandle")
consoleHandle, _,_ := colorHandle.Call(uintptr(count))
colorSet := objDll.NewProc("SetConsoleTextAttribute")
colorSet.Call(consoleHandle, uintptr(*cc))
}
调用API 实现命令行字体变色。
CMD都是一种背景颜色 一种字体颜色,从头到尾,改了一个就全部改变了。
有些同学喜欢一行一个颜色,一段话使用一种颜色,分开现实,以上程序即可实现。
使用方法:cc 1~255