找回密码
 加入
搜索
查看: 118|回复: 3

能否让控制台程序的输出真彩字符?

[复制链接]
发表于 2024-6-5 21:50:25 | 显示全部楼层 |阅读模式
_ConsoleWriteColor.au3  可以让编译的控制台程序输出彩色字符(16色)。自从win10以后,控制台已经可以支持更多颜色(256色,真彩色)

那么,有无方法让编译的控制台程序输出更多彩色字符呢?

发表于 2024-6-6 08:58:19 | 显示全部楼层
Func ShowHelp()
        Local $hStdHandle,$i,$Color[17]
        $Color[0]="Black"
        $Color[1]="Bule"
        $Color[2]="Green"
        $Color[3]="Aqua"
        $Color[4]="Red"
        $Color[5]="Purple"
        $Color[6]="Yellow"
        $Color[7]="White"
        $Color[8]="Grey"
        $Color[9]="Light Blue"
        $Color[10]="Light Green"
        $Color[11]="Light Aqua"
        $Color[12]="Light Red"
        $Color[13]="Light Purple" 
        $Color[14]="Light Yellow"
        $Color[15]="Bright White"
        $hStdHandle = _Console_GetStdHandle()
        _Console_SetConsoleTextAttribute($hStdHandle,11)
        _Console_WriteConsole($hStdHandle,"This program is used to show the Lattice diagram file into CMD windows by CCCC 03/01/2013"&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,13)
        _Console_WriteConsole($hStdHandle,"Version:        TypePlus v3.1"&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,14)
        _Console_WriteConsole($hStdHandle,"Usage:"&@CRLF&"        TypePlus.exe [BKColor] [FrontColor] [[FilePath] or [String]]"&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,9)
        _Console_WriteConsole($hStdHandle,"Color:"&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,10)
        _Console_WriteConsole($hStdHandle,"        "&0&"-->["&$Color[0]&"]         ")
        _Console_SetConsoleTextAttribute($hStdHandle,0*16)
        _Console_WriteConsole($hStdHandle,"    ")    
        _Console_SetConsoleTextAttribute($hStdHandle,10)
        _Console_WriteConsole($hStdHandle,"        "&0+8&"-->["&$Color[0+8]&"]                ")
        _Console_SetConsoleTextAttribute($hStdHandle,(0+8)*16)
        _Console_WriteConsole($hStdHandle,"    "&@CRLF)
        For $i=1 To 7 
                _Console_SetConsoleTextAttribute($hStdHandle,10)
                _Console_WriteConsole($hStdHandle,"        "&$i&"-->["&$Color[$i]&"]        ")
                _Console_SetConsoleTextAttribute($hStdHandle,$i*16)
                _Console_WriteConsole($hStdHandle,"    ")    
                _Console_SetConsoleTextAttribute($hStdHandle,10)
                _Console_WriteConsole($hStdHandle,"        "&$i+8&"-->["&$Color[$i+8]&"]        ")
                _Console_SetConsoleTextAttribute($hStdHandle,($i+8)*16)
                _Console_WriteConsole($hStdHandle,"    "&@CRLF)
        Next
        _Console_SetConsoleTextAttribute($hStdHandle,15)
        _Console_WriteConsole($hStdHandle,"Return Code:"&@CRLF&"        0: PASS"&@CRLF&"        1: FAIL"&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,14)
        _Console_WriteConsole($hStdHandle,"Example:"&@CRLF&"        TypePlus 0 14 d:\BIOS.txt."&@CRLF&'        TypePlus 0 14 "This is a Test!!"'&@CRLF)
        _Console_SetConsoleTextAttribute($hStdHandle,7)
EndFunc

Func _Console_GetStdHandle($iStdHandle = -11)
        Local $hStdHandle

        $hStdHandle = DllCall("kernel32.dll", "hWnd", "GetStdHandle", "dword", $iStdHandle)
        Return $hStdHandle[0]
EndFunc        ;==>_Console_GetStdHandle()


Func _Console_SetConsoleTextAttribute($hStdHandle, $iColor)
        Local $iResult

        $iResult = DllCall("kernel32.dll", "int", "SetConsoleTextAttribute", _
                        "hWnd", $hStdHandle, "dword", $iColor)
        Return $iResult[0] <> 0
EndFunc        ;==>_Console_SetConsoleTextAttribute()


Func _Console_WriteConsole($hStdHandle, $sData = "")
        Local $iResult, $tDataWritten

        $tDataWritten = DllStructCreate("char[" & StringLen($sData) + 1 & "]")
        DllStructSetData($tDataWritten, 1, $sData)

        $iResult = DllCall("kernel32.dll", "int", "WriteConsole", _
                        "hWnd", $hStdHandle, _
                        "ptr", DllStructGetPtr($tDataWritten), _
                        "dword", StringLen($sData), _
                        "dword*", 0, "ptr", 0)
        $tDataWritten = 0
        Return $iResult[0] <> 0
EndFunc        ;==>_Console_WriteConsole()



正好我10年前玩过!!

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?加入

×
 楼主| 发表于 2024-6-6 09:52:18 | 显示全部楼层
kemyliu 发表于 2024-6-6 08:58
正好我10年前玩过!!

谢谢回复
不过请仔细看一楼帖子。不是要16色的,是256色/真彩色
发表于 2024-6-6 13:07:56 | 显示全部楼层
kemyliu 发表于 2024-6-6 08:58
正好我10年前玩过!!

不错,先玩玩16色
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-6-15 02:27 , Processed in 0.080350 second(s), 21 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表