[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
返回列表 发帖
回复 5# cmd1152
当然可以
Why join the navy, if you can be a pirate? - Steve Jobs

TOP

回复 4# HOPE2021


    声明 部分的代码一直报错误,谁能给我一个正版VB6.0????
梦依旧在,只是,心有余而力渐有不足
年年岁岁花相似,岁岁年年人不同

TOP

回复 4# HOPE2021


    我可否把他改成16BT颜色?
梦依旧在,只是,心有余而力渐有不足
年年岁岁花相似,岁岁年年人不同

TOP

回复 3# HOPE2021
源码:
  1. Option Explicit
  2. Public Declare Function FreeConsole Lib "kernel32" () As Long
  3. Public Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
  4. Public Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Long) As Long
  5. Public Declare Function LstrLen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As String) As Long
  6. Private Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal hConsoleOutput As Long, ByVal wAttributes As Long) As Long
  7. Public Declare Function WriteConsole Lib "kernel32" Alias "WriteConsoleA" (ByVal hConsoleOutput As Long, ByVal lpBuffer As Any, ByVal nNumberOfCharsToWrite As Long, lpNumberOfCharsWritten As Long, lpReserved As Any) As Long
  8. Public Const STD_OUTPUT_HANDLE = -11&
  9. Public hConsoleOut As Long
  10. Public Sub Initialize()
  11.     hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE)
  12. End Sub
  13. Public Sub Terminate()
  14.     Call FreeConsole
  15.     Call CloseHandle(hConsoleOut)
  16. End Sub
  17. Public Sub Echo(ByVal szOut As String)
  18.     WriteConsole hConsoleOut, szOut, LstrLen(szOut), vbNull, vbNull
  19. End Sub
  20. Sub Main()
  21.     On Error Resume Next
  22.     Dim Cmd
  23.     Dim i
  24.     Dim j
  25.     Call Initialize
  26.     Dim Color___ As Long
  27.     If Command = "" Then
  28.         Call Echo(vbCrLf & "没有命令参数,操作失败" & vbCrLf)
  29.         Call Help_
  30.     End If
  31.     If Left(UCase(Command), 2) = "/H" Then
  32.         Call Help_
  33.         Call Terminate
  34.         Exit Sub
  35.     End If
  36.     If Left(UCase(Command), 2) = "/?" Then
  37.         Call Help_
  38.         Call Terminate
  39.         Exit Sub
  40.     End If
  41.     Color___ = Command
  42.     If Not Left(UCase(Command), 2) = "/H" Then
  43.         Dim Handle
  44.         Handle = GetStdHandle(STD_OUTPUT_HANDLE)
  45.         If IsNumeric(Color___) = True Then
  46.             Call SetConsoleTextAttribute(Handle, Color___)
  47.             Call Terminate
  48.             End
  49.         End If
  50.     Call Echo("命令参数不正确" & vbCrLf)
  51.     Call Terminate
  52.     End If
  53. End Sub
  54. Function Help_()
  55.     Call Echo(vbCrLf & "Hope Colour [Version 1.0.0000]" & vbCrLf)
  56.     Call Echo("(C) Copyright 2016-2021 Hope Corp." & vbCrLf & vbCrLf)
  57.     Call Echo("本程序用于让命令行实现彩色显示" & vbCrLf & vbCrLf)
  58.     Call Echo("Colour /H                   - 查询帮助" & vbCrLf & vbCrLf)
  59.     Call Echo("Colour /?                   - 查询帮助" & vbCrLf & vbCrLf)
  60.     Call Echo("Colour ColourCode           - 从下一行命令开始,进行与ColourCode关联的颜色" & vbCrLf)
  61.     Call Echo("                            - ColourCode是颜色代码,可以是任意一个0~255的正整数" & vbCrLf)
  62.     Call Echo("                            - 下面是ColourCode的色卡" & vbCrLf & vbCrLf)
  63.     Dim i
  64.     For i = 0 To 255
  65.         Dim Handle
  66.         Handle = GetStdHandle(STD_OUTPUT_HANDLE)
  67.         Call SetConsoleTextAttribute(Handle, i)
  68.         Call Echo(" " & i & " ")
  69.         Call SetConsoleTextAttribute(Handle, 0)
  70.         Call Echo(Chr(9))
  71.     Next
  72.     Call Echo(vbCrLf)
  73.     Call SetConsoleTextAttribute(Handle, 7)
  74.     Call Terminate
  75.     End
  76. End Function
复制代码
Why join the navy, if you can be a pirate? - Steve Jobs

TOP

回复 2# HOPE2021
FindStr做不到的事:彩色显示重定向符:
  1. @Echo off
  2. Mode Con: Cols=80 Lines=25
  3. Title Colour Test
  4. Set "Line="
  5. Set "Line2="
  6. For /l %%i in (1,1,80) do (
  7. Call :Line
  8. Call :Line2
  9. )
  10. For /l %%i in (0,1,255) do (
  11. Colour %%i
  12. Call :Echo2
  13. )
  14. @Pause > nul
  15. @Exit /b
  16. :Line
  17. Set "Line=%Line%^<"
  18. @Goto :eof
  19. :Line2
  20. Set "Line2=%Line2%^>"
  21. @Goto :eof
  22. :Echo2
  23. Set /a Rand=%Random%%%2
  24. If %Rand% Equ 0 (
  25. Set /p Str=%Line%<nul
  26. )
  27. If %Rand% Equ 1 (
  28. Set /p Str=%Line2%<nul
  29. )
  30. @Goto :eof
复制代码
Why join the navy, if you can be a pirate? - Steve Jobs

TOP

本帖最后由 HOPE2021 于 2021-10-5 12:46 编辑

回复 1# HOPE2021
使用Colour.Exe制作的彩虹:
  1. @Echo off
  2. Mode Con: Cols=80 Lines=25
  3. Title Colour Test
  4. Set "Line="
  5. For /l %%i in (1,1,80) do (
  6. Call :Line
  7. )
  8. For /l %%i in (0,1,255) do (
  9. Colour %%i
  10. Set /p Str=%Line%<nul
  11. )
  12. @Pause > nul
  13. @Exit /b
  14. :Line
  15. Set "Line=%Line%#"
  16. @Goto :eof
复制代码
Why join the navy, if you can be a pirate? - Steve Jobs

TOP

返回列表