Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- REM Three files follow
- REM ColourText.bat
- REM This file compiles ColourText.vb to ColourText.exe using the system VB.NET compiler.
- REM ColourText.exe Changes the colour of text in the command prompt. Unlike inbuilt commands it can change just one line.
- "C:\Windows\Microsoft.NET\Framework\v4.0.30319\vbc.exe" /target:exe /out:"%~dp0\ColourText.exe" "%~dp0\ColourText.vb" /verbose
- pause
- --------------------------------------------------
- 'ColourText.vb
- Imports System
- Imports System.IO
- Imports System.Runtime.InteropServices
- Imports Microsoft.Win32
- Public Module MyApplication
- Public Declare Function GetStdHandle Lib "kernel32" (ByVal nStdHandle As Integer) As Integer
- Public Declare Function SetConsoleTextAttribute Lib "kernel32" (ByVal hConsoleOutput As Integer, ByVal wAttributes As Integer) As Integer
- Public Const STD_ERROR_HANDLE = -12&
- Public Const STD_INPUT_HANDLE = -10&
- Public Const STD_OUTPUT_HANDLE = -11&
- Sub Main()
- Dim hOut as Integer
- Dim Ret as Integer
- Dim Colour As Integer
- Dim Colour1 As Integer
- Dim Text As String
- hOut = GetStdHandle(STD_OUTPUT_HANDLE)
- Colour = CLng("&h" & Split(Command(), " ")(0))
- Colour1 = Clng("&h" & Split(Command(), " ")(1))
- Text = Mid(Command(), 7)
- Ret = SetConsoleTextAttribute(hOut, Colour)
- Console.Out.WriteLine(text)
- Ret = SetConsoleTextAttribute(hOut, Colour1)
- End Sub
- End Module
- -----------------------------------------------
- ColourTextHelp.txt
- To use
- ColourText <ColourOfText> <ColourOfTextWhenFinished> [Text]
- Also the CLS command becomes interesting. Color command without parameters resets all colours to startup colours.
- To get the colour code add the following numbers together. Use Calculator in programmers mode. These are hex numbers. They can be added together eg Red + Blue + FG Intensity = 13 = D. As 10+ wasn't used the background will be black.
- Colour codes MUST be two characters, eg 08 not 8.
- FOREGROUND_RED = &H4 ' text color contains red.
- FOREGROUND_INTENSITY = &H8 ' text color is intensified.
- FOREGROUND_GREEN = &H2 ' text color contains green.
- FOREGROUND_BLUE = &H1 ' text color contains blue.
- BACKGROUND_BLUE = &H10 ' background color contains blue.
- BACKGROUND_GREEN = &H20 ' background color contains green.
- BACKGROUND_INTENSITY = &H80 ' background color is intensified.
- BACKGROUND_RED = &H40 ' background color contains red.
- So black background is 0 while white is F0 (adding 10 + 20 + 40 + 80). Red on white is f4.
Advertisement
Add Comment
Please, Sign In to add comment