Introduction:

Hey friends! If you guys are beginners in the field of C++ programming and you want to make a simple and small C++ graphical program. Then this page is for you. On this page, we will see how you can design a simple loading bar.

             Before creating this program, we need to first add the graphics.h library to your compiler. I am using Dev C++ here. If you are using any other compiler, then you have to put this graphics library in that compiler.

Procedure to add graphics. h library:

  1. First, download the latest version of Dev C++ IDE otherwise you can download code-block. But my suggestion is to use Dev C++. Because this IDE is pretty much easy to use. – link
  2. Download the graphics header files from the given drive. – link
  3. Now, extract the downloaded zip file. You can see the folder named Graphics in Dev C++. From this folder copy the graphics and winbgim files.
  4. Then, go to the location where Dev C++ is installed.  On my computer, it is in C drive. Go inside the folder named Dev-Cpp and then click on MinGW64 folder. Then go to the include folder and paste the copied files. My path: C:\Dev-Cpp\MinGW64\include
  5. Then again go to that downloaded graphics folder and copy the libbgi. a file and paste it into the lib folder of the Dev C++ installer. Path C:\Dev-Cpp\MinGW64\lib
  6. Now, go one more time to that folder and copy the ConsoleAppGraphics.template and ConsoleApp_cpp_graph.txt files and paste them inside the Templates folder of the Dev C++ installer location. Path C:\Dev-Cpp\Templates
  7. Now we are done with configuring the Dev C++ to support graphics programming.
  8. Now, open Dev C++ IDE. Click on File and then click on New after that click on Project.
  9. Now, select the Console Graphics option.
  10. Now, give a project name and make sure the selected language is C++.
  11. Now, click on Project menu and choose Project Options.
  12. Now, go to the Parameters tab in the Linker field, and enter the following text:

            -lbgi

            -lgdi32

            -lcomdlg32

            -luuid

            -loleaut32

            -lole32

     13. After completion of your entry, just click on the OK button.

That’s all! Here we  completed our graphics support setup. Now we can write any graphics code in C++ language in Dev C++.

Note: If you are using a different IDE and this solution is not working on your IDE then you can search other solutions on google according to your IDE.

If you have successfully completed this work then we are ready to make a loading bar.

Program info:

Project Name

Loading bar in C++ (C++ loading screen)

About

This program is a C++ simple and easy graphics program for beginners.

Type

C++ graphics program

Published by

Codes Gallery

Developer

Chetan Bedakihale


Instructions to make loading bar:

  • First of all, we have to include 3 main header files in our code to make a loading bar. Yes, graphics. h is also there in those three header files. Graphics.h is very important in those three header files; without that, we cannot do any activity related to any graphics. Those header files are named graphics.h, dos. h, and conio. h.

#include "graphics.h"
#include "conio.h"
#include "dos.h"

  • Now, we will create the main function and, in that function, we will write the code of the loading bar.

int main(){

}

  • Now first of all we will initialize the graphics driver in this main function. After that, to initialize the graphics system, we call the initgraph function. This function loads the graphics driver and puts the system into graphics mode. As an example, check the code below.

int gd = DETECT, gm;
	initgraph(&gd,&gm, "C:\\TC\\BGI");

  • After that, we will write the actual code for the loading bar. So first of all, we would get a text printed. That text will tell that loading is happening. To print that text we will use the outtextxy() function which is located in graphics. h.

	outtextxy(200,200,"Loading...");
  
Loading bar in C++ | C++ loading screen


  • Now we will draw a rectangle over that text which will serve as the outline of the loading bar.

	rectangle(199,179,350,191);
    
Loading bar in C++ | C++ loading screen


  • Now, we will create a for loop in which we will draw another rectangle. This rectangle will be slightly smaller than the first rectangle and will be inside it. This rectangle will keep increasing its length after every 100ms until the end of the first rectangle.

	for(int i = 0; i < 150; i++){
		setcolor(2);
		rectangle(200,180,200+i,190);
		delay(100);
	}
	
	getch();
	closegraph();

Here we successfully made our loading bar using C++. Output is given below:

Full Program:







Post a Comment

You are welcome to share your ideas with me in the comments!

Previous Post Next Post