Monday, June 14, 2010

My simple batch file tutorial [Part 4]

In this part 4 , I will show you how to customize the display for the batch file broadcasting.

Actually besides the standard black background and white foreground, you can actually customize the display colours to your liking 

Such as matrix style or even blue screen of death style. 



From the above, as you can see, you can customize the display messages .

I give you the sample code of the both codes above.

Matrix :

@echo off
:: This is the display of the matrix style
color 0a
echo Welcome to the Matrix, Neo!
pause

Blue Screen of Death:

@echo off
rem This is the display of blue screen of death
color 1f
echo The program had encountered unexpected runtime errors . :(
pause

As you can see, we can see some unfamiliar command again 

Let us starts by the :: and rem

:: and rem command is the comments block that is left by programmers which do not interfere with programs flow but it is important to remind the programmers what can the particular piece of programming can do 

What does it do is the line of word which are after the :: or rem are ignored by the compiler. It is basically the comments that reminds you of particular things about the programs part and miscellaneous stuffs and it can be put in anywhere inside a batch programs but for small programs ,it is usually not used very much.

Now we move on the colouring but due to it comes from America, we had to spell it the America way , C-O-L-O-R without a "U". 

color command is used to colour the background and foreground  

By changing the hexadecimal value of the color line command, we can change to any colours that we like.

As you can see from example above there are 2 digits values after the color command line. 

color 0a and color 1f

The digits on the left represents the background colours and the right digits represents the foreground colours. 
Confused about background and foreground ? 
Let's say, u take a blue pen to write on a piece of orange paper.

The letters that you write out with blue pens are called foregrounds while the orange paper are called backgrounds. 

If you are still confused, I don't know how to make you understand about it. 

Lets get back to the color command as we said earlier the left digits represents the background colours and right digits represents the foreground colours.
Anyway, if we want to change the foregrounds colours , we only need to input 1 digits only which represents the foreground values.

For example color 0a in the matrix example style can be represented by color a and we still get the same result. 

I give you the list of the table of hexadecimal values represents their colours.
This is tested true for Window Vista and on white background and unless I am blind colour, this is supposed to be correct
(I do not know the name of colours very well , so if you know post a comment yah) 

0   -   Black 
1   -   Blue
2   -   Green
3   -   Blueish Green
4   -   Dark Red
5   -   Purple
6   -   Gold
7   -   Light Gray
8   -   Dark Gray
9   -   Light Blue
a   -   Yellowish Green
b   -   Light Blueish Green
c   -   Red
d   -   Light purple
e   -   Yellow
f   -   White

Before ending this part, I include how to modify the title bar of your programs. 

I reuse the Matrix samples again, as you can see on the title bar above is file location where the MS-DOS Command Prompt is launched. You can change that by using title command

title command is used to change the title bar.


If you find the title is a little bit boring , you can pretend that you hacked into Agent Smith e mail inbox and found something interesting. 


How do you do it ? Simple add the title command in the beginning part of batch programming. 

@echo off
:: This is the display of the matrix style
title Agent Smith Inbox
color 0a
echo Welcome to the Matrix, Neo!
pause


Let us continue to more advances part in next part tutorial.

No comments:

Another random post to read ? Come !

Related Posts with Thumbnails