Creating Installation Bar in C++.

0 23
Avatar for Ceddy-lim
2 years ago

I want to share to you how to create an installation bar in c++ without using any special tool.

First thing that we will going to do is create a function for progress bar and color codes so that we can input a parameter to our color codes function..

The codes for making the color codes is down below :

void colorCode(int colors){
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, colors);
}

You can rename it as you wish and change the parameter name. So this function allows you to add color to your program. We all know that if we want to apply color then all we have to is like this :

system("color 0A") ; //color green

In my first article I listed all of the color code.

So why we create a function for color if there's already a built in color.? Well yes theres already a built in color but I just wanted to show how to create a color function to apply the parameter because I want to help you understand more what is the use of parameter..

This next block of codes is on how to create a progressbar and calling the color codes function

void installation(){

    font();

	for (int i=1;i<=100;i+=1){

		system("cls");
		colorCode(10000);
		cout<<"\n\n\n\n\n\n\n\t\t\t";
		cout<<i<<"% Successfully Installed!...\n\n\t\t\n\t\t";

		cout<<"";

		for (int j=0; j<i;j+=2){

			colorCode(120+j);
			cout<<" ";
			colorCode(15);

		}
		Sleep(100);
		if(i==90 || i==50 || i==96 || i==83){
			Sleep(500);
		}
	}


}

As you Can see its just the same in creating a loading bar but the difference is we apply a different color.

The next block of codes is on how to make the progress bar Bigger :

void font(){
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 30;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

}

So if we will going to combine all of this block of codes then it will be the result 👇👇👇👇👇👇

Source Code :

#include <iostream>
#include <windows.h>

void font();
void colorCode();
void installation();
using namespace std;

int main()
{
    installation();
    return 0;
}

void colorCode(int colors){
HANDLE hConsole;
hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(hConsole, colors);
}


void installation(){

    font();

	for (int i=1;i<=100;i+=1){

		system("cls");
		colorCode(10000);
		cout<<"\n\n\n\n\n\n\n\t\t\t";
		cout<<i<<"% Successfully Installed!...\n\n\t\t\n\t\t";

		cout<<"";

		for (int j=0; j<i;j+=2){

			colorCode(120+j);
			cout<<" ";
			colorCode(15);

		}
		Sleep(100);
		if(i==90 || i==50 || i==96 || i==83){
			Sleep(500);
		}
	}


}

void font(){
CONSOLE_FONT_INFOEX cfi;
cfi.cbSize = sizeof(cfi);
cfi.nFont = 0;
cfi.dwFontSize.X = 0;
cfi.dwFontSize.Y = 30;
cfi.FontFamily = FF_DONTCARE;
cfi.FontWeight = FW_NORMAL;
std::wcscpy(cfi.FaceName, L"Consolas");
SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);

}

The OutPut::

If you want to learn more about c++ then you can check me out on my youtube channel!.

1
$ 0.29
$ 0.29 from @TheRandomRewarder
Sponsors of Ceddy-lim
empty
empty
empty
Avatar for Ceddy-lim
2 years ago

Comments