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