Helpful Information
 
 
Category: Computer Programming
ňa simple code in c++

Hi
This is a simple code in c++ that defines a button class to draw a button
#include <graphics.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
#include <string.h>

class button
{
private:
int x;
int y;
char *s;
public:
void draw()
{
if (textwidth(s)>50)
{
setfillstyle(SOLID_FILL, 7);
bar(x, y, x+textwidth(s)+4, y+20);
setcolor(15);
line(x, y, x+textwidth(s)+4, y);
line(x, y, x, y+20);
setcolor(8);
line(x+textwidth(s)+4, y, x+textwidth(s)+4, y+20);
line(x, y+20, x+textwidth(s)+4, y+20);
setcolor(0);
outtextxy(x+2, y+5, s);
return;
}
setfillstyle(SOLID_FILL, 7);
bar(x, y, x+45, y+20);
setcolor(15);
line(x, y, x+45, y);
line(x, y, x, y+20);
setcolor(8);
line(x+45, y, x+45, y+20);
line(x, y+20, x+45, y+20);
setcolor(0);
outtextxy(x+4, y+5, s);
};
void set(int a, int b, char *c)
{
x=a;
y=b;
strcpy(s, c);
};
};
int main(void)
{
int gdriver = DETECT, gmode, errorcode;
button c;
initgraph(&gdriver, &gmode, "");
c.set(100, 100, "Aymen");
c.draw();
delay(5000);
closegraph();
return 0;
}










privacy (GDPR)