Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How do i create a button in C++

+4 votes
asked Mar 21, 2023 by Conner Mason (160 points)
I'm trying to create some buttons for a calculator I'm creating ( I'm very new to coding and this is my first actual project). I just want a button for addition, subtraction, multiplication, and division.

2 Answers

0 votes
answered Mar 23, 2023 by Peter Minarik (84,720 points)
For your very first program, I think you should just do a console application and add a GUI at a later project. Typically you'd use a 3rd party library, such as QT.

You could also use IDEs to help you visually design the UI of your application, such as Visual Studio.
0 votes
answered Mar 27, 2023 by Java Codes (360 points)
#include <math.h>
#include <conio.h>
#include <iostream>
#include <winbgim.h>
#include <stdlib.h>
//#include <cstdlib.h>

using namespace std;
const int ANCHO = 720, ALTO = 720;
void titulo(int x, int y, char *n="    "){
  outtextxy(x,y,n);
  } 

int prueba(int x, int y)
{
  rectangle(x,y,x+70,y+20);
  
  if(mousex()>x && mousex()<x+70 && mousey()>y && mousey()<y+20 && ismouseclick(WM_LBUTTONDOWN))
    {   
	    clearmouseclick(WM_LBUTTONDOWN);
    	return 1;
	}
  else
    {
    	clearmouseclick(WM_LBUTTONDOWN);
  	    return 0;
    }     
}

void estado (int x, int y, int c1, int c2)
{
    if(mousex()>x && mousex()<x+70 && mousey()>y && mousey()<y+20 )
	{
    	setcolor(c1);
	}
	else
	{
		setcolor(c2);
	}    
}

/*****************************************************************************************************************************/  
int main(int argc, char *argv[]) {
	initwindow( 400, 400, "Botón para salir", 300,200 );
	setbkcolor(RGB(63,199,168));
	cleardevice();
	
	while(true)
    {
     
	 titulo(100,40,"SALIR");
	 estado(100,42,2,15);
	 if (prueba(90,40))
	   {return 0;}
	 
	}		
	
	getch();	
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...