How to use getmaxx() and getmaxy() Function in C Language

getmaxx() and getmaxy() Function in C or C++ Language

Introduction :

The C or C++ programming language is very famous for creating various types of applications such as graphical programs. When working with graphics using C or C++ language, it is essential to understand the dimensions of the screen or drawing area to ensure your graphics are displayed correctly.

The getmaxx() and getmaxy() functions are used to retrieve the maximum X and Y coordinates of the screen or window. These functions allow you to create graphics that are responsive to different screen sizes. The getmaxx() and getmaxy() functions are part of the graphics.h library of Turbo C++ IDE, which is commonly used for graphics programming in C or C++ language. To create graphics that dynamically adapt to various screen or window sizes, any programmer must use these functions as essential tools.

To create visually appealing and responsive graphical applications, getmaxx() and getmaxy() functions are very important in the programming world. In this article, I shall explore you how to use getmaxx() and getmaxy() functions for determine the maximum x and y coordinates of your screen or graphics window. Here, you can learn how to use getmaxx() and getmaxy() functions in C or C++ programming language.

What are getmaxx() and getmaxy() Functions :

The getmaxx() and getmaxy() are not standard library functions of C or C++ programming language. You can use these function after include graphics.h library in Turbo C++ IDE. The getmaxx() and getmaxy() functions are typically used in graphics programming to determine the dimensions of the canvas where you can draw various shapes, lines and other graphical elements. Instead of specific values, you can use these functions to ensure your graphics are displayed correctly on various devices.

getmaxx() :

The getmaxx() function is used to retrieve the maximum X coordinate (horizontal resolution) of the screen or graphics window. In a console application, this represents the number of columns available for drawing. In a graphical application, it can be used to determine the maximum width of the drawing area or graphics window.

getmaxy() :

The getmaxy() function is used to retrieve the maximum Y coordinate (vertical resolution) of the screen or graphics window. In a console application, it indicates the number of rows available for drawing. In a graphical application, it represents the maximum height of the drawing area or graphics window.

The values returned by getmaxx() and getmaxy() in graphics programming can vary depending on the graphics mode set for your program. Different graphics modes have different resolutions and coordinate systems. CGA Graphics (320×200) where getmaxx() and getmaxy() would return 319 and 199 respectively. EGA Graphics (640×350) where getmaxx() and getmaxy() would return 639 and 349 respectively. In VGA Graphics (640×480), you can get 639 and 479 from getmaxx() and getmaxy() respectively.

Declaration :

Following code are the syntax of getmaxx() and getmaxy() functions.
int getmaxx(void);
int getmaxy(void);

Where getmaxx() function returns the maximum x value for the current graphics driver and mode. The getmaxy() function returns the maximum y value for the current graphics driver and mode.

About the program :

When you run this program in the Turbo C++ IDE, initialize a graphics window and then retrieves the maximum X and Y coordinates of the graphics mode. Finally, you can see the maximum x and y coordinates of the graphics mode on the screen.

Explanation of the program :

In the program, first You need to include the graphics.h header file for graphics functions, the stdio.h header file for standard input and output function like printf() and the conio.h header file for console input/output function like getch(). In the main() function, declares two integer variables “max_x” and “max_y” to store the maximum X and Y coordinates, respectively. You have to also declare two more integers “graphic_driver” and “graphic_mode”. They are used to specify the graphics driver and graphics mode when initializing the graphics mode.

Before using getmaxx() and getmaxy() functions, you have to initialize the graphics mode. You can use initgraph() function to initialize the graphics mode. After initializing the graphics mode, you can use getmaxx() and getmaxy() to determine the screen or window dimensions and store in “max_x” and “max_y” variables respectively. Now, you can display the values of maximum x and y coordinate of the graphics mode on the screen using printf() function. Before closing the program using closegraph() function, you can use getch() function for better view the output on the screen.

How run the program :

To run the program, you have to install the Turbo C++ IDE on your pc. Now open the Turbo C++ IDE, create a C or C++ file with .c or .cpp extension. Then copy the below code and paste in your C or C++ file of the Turbo C++ IDE. Do you know how to copy paste in the Turbo C++ IDE, if not just click here. You can also see how to use graphics.h in Turbo C++ IDE in my other post. Now run the program on your pc.

Code for getmaxx() and getmaxy() functions :

The following code is used for getmaxx() and getmaxy() functions in C or C++ programming language.

/*Developed by Puskar Jasu*/
#include <graphics.h>
#include <stdio.h>
#include <conio.h>
int main(void)
{
   int max_x, max_y;
  int graphic_driver = DETECT, graphic_mode;
   initgraph(&graphic_driver, &graphic_mode, "//turboc3/bgi");
 max_x = getmaxx();
    max_y = getmaxy();
    printf("Maximum X coordinate of the graphics mode = %d\n", max_x);
    printf("Maximum Y coordinate of the graphics mode = %d\n", max_y);
   getch();
   closegraph();
   return 0;
}

Output :

You can see the output of the above program like below image on your pc.

output of getmaxx() and getmaxy() functions

Conclusion :

Understanding the dimensions of your screen or graphics window is important when creating graphical applications in C or C++ programming language. The getmaxx() and getmaxy() functions in the graphics.h library gives a way to obtain this information. After completing the above article, you have learned how use getmaxx() and getmaxy() functions in your graphics program by C or C++ programming language. Thank you for visiting my site.

Scroll to Top