473,394 Members | 1,821 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

exit function

Hi Guys.

im new in c programming using turbo c

i have just created a box of exit button and now want to make the exit work when i use the mouse so it can close the program.

does any1 here have any idea how and what code i is it to make the exit button function

please help
Mar 8 '07 #1
6 6230
sicarie
4,677 Expert Mod 4TB
Hi Guys.

im new in c programming using turbo c

i have just created a box of exit button and now want to make the exit work when i use the mouse so it can close the program.

does any1 here have any idea how and what code i is it to make the exit button function

please help
Could you be a bit more specific? Are you looking for something like the 'exit( int )' function, or an implementation of how to register a mouse click over the button...?
Mar 8 '07 #2
Could you be a bit more specific? Are you looking for something like the 'exit( int )' function, or an implementation of how to register a mouse click over the button...?
Well basically what i done so far is that i have created a basic square button for exit and now i want to know what is the codeing for the exit button, so that when i use the mouse.. and click on the button it will then exit the program
i hope you understand it.
Mar 8 '07 #3
can any1 help me please
Mar 8 '07 #4
vermarajeev
180 100+
can any1 help me please
Hi.. I cannot tell you exactly what you have to code but I can just give an idea. Whenever you want to exit on mouse clicking use closegraph(). Here is the sample code program which I had used when I was using graphics programming many years back

Expand|Select|Wrap|Line Numbers
  1. void main(int argc,char *argv[])
  2. {
  3.    int row,column,gd=DETECT,gm,i,j,temp;FILE *fp;char t[15];
  4.    /* Check if arguments more than 2 */
  5.    if (argc>2)
  6.    {
  7.      clrscr();
  8.      printf("Too many arguments !!\n\nGraphics Editor terminating...\n");
  9.      delay(900);
  10.      exit(0);
  11.    }
  12.    if(argc==1) //if only draweasy is specified, then filename is default
  13.     strcpy(filename,"noname.drw");
  14.    else           //if exactly 2 arguments are specified
  15.    {
  16.     fnsplit(argv[1],drive,dir,file,ext); //split path name into parts
  17.     if (strcmp(ext,".drw")!=0)         //if extension is not .drw
  18.     {
  19.       if (strcmp(ext,"")==0)         //if no extension is present
  20.       {
  21.         strcpy(ext,".drw");         //define extension to be .drw
  22.         strcpy(t,argv[1]);         //save argument[1] in 't'
  23.         strcat(t,ext);             //concatinate with extension
  24.         strcpy(filename,t);         //copy it to filename
  25.       }
  26.       else                    //if extension is not .drw
  27.       {
  28.         clrscr();
  29.         printf("File should have a '.drw' extension\n");
  30.         sleep(2);
  31.         exit(0);
  32.       }
  33.     }
  34.     else              //if .drw is the given extension
  35.         strcpy(filename,argv[1]);
  36.     fp=fopen(filename,"r");      //check if file already exists.
  37.     if (fp!=NULL)          //if exists, then,
  38.     {
  39.       bkColor=fgetc(fp);
  40.       for (i=DRAW_LT+1;i<DRAW_RT;i++)
  41.       for (j=DRAW_TOP+1;j<DRAW_BOT;j++)
  42.       if ((temp=fgetc(fp))!=bkColor)
  43.       {
  44.         colorChoice=temp;
  45.         break;
  46.       }
  47.       fclose(fp);
  48.     }
  49.    }
  50.    initgraph(&gd,&gm,"c:\\tc\\bgi");
  51.    cleardevice();
  52.    reset_mouse();
  53.   // WelcomeScreen1();
  54.    WelcomeScreen2();
  55.    cleardevice();
  56.    reset_mouse();
  57.    cleardevice();
  58.    reset_mouse();
  59.    mainScreen();
  60.    if(argc==2)
  61.     ld(filename);
  62.    fileNameLine(filename);
  63.    set_mouse_rangeh(0,MAX_COL);
  64.    set_mouse_rangev(0,MAX_ROW);
  65.    show_mouse();
  66.    while (!over)
  67.    {
  68.      get_mouse_position(&row,&column);
  69.      update_mouse_cursor(row,column);
  70.      if (mouse_button_press())
  71.     check_area_of_mouse(row,column);
  72.      display_current_mouse_position();
  73.    }
  74.    closegraph();
  75. }
Here over is a flag where I set it to true whenever I want to exit.

Hope it helps you.
Mar 9 '07 #5
/* check the colours !!!! */
int black = 0;
int deepblue = 1;
int deepgreen = 2;
int deepcyan = 3;
int deepred = 4;
int deepmagenta= 5;
int brown = 6;
int gray = 7;
int blue = 8;
int green = 10;
int cyan = 11;
int red = 12;
int magenta = 13;
int yellow = 14;
int white = 15;

int yline0= 0 ; /* position of a Y line */
int yline1= 20 ; /* position of a Y line */
int yline2= 40 ; /* position of a Y line */
int yline3= 60 ; /* position of a Y line */
int yline4= 80 ; /* position of a Y line */
int yline5= 100 ; /* position of a Y line */
int yline6= 120 ; /* position of a Y line */
int yline7= 140; /* position of a Y line */
int yline8= 160; /* position of a Y line */
int yline9= 180; /* position of a Y line */
int yline10 = 200 ; /* position of a Y line */
int yline11 = 220 ; /* position of a Y line */
int yline12 = 240 ; /* position of a Y line */
int yline13 = 260 ; /* position of a Y line */
int yline14 = 280 ; /* position of a Y line */
int yline15 = 300 ; /* position of a Y line */
int yline16 = 320 ; /* position of a Y line */
int yline17 = 340; /* position of a Y line */
int yline18 = 360 ; /* position of a Y line */
int yline19 = 380 ; /* position of a Y line */
int yline20 = 400 ; /* position of a Y line */
int yline21 = 420 ; /* position of a Y line */
int yline22 = 440 ; /* position of a Y line */
int yline23 = 460 ; /* position of a Y line */
void heading(char *string);
void centreline(char *string);
void gcls(void) ;
void gsolidrectangle(int x1, int y1, int x2, int y2,int col);

//mouse int function
int GetX(void);
int GetY(void);
int GetKey(void);
void ShowCursor(void);
void HideCursor(void);
int ButtonStatus(void);
void SetMouseMode(int);
void PrintMousePosition(void);
void UpdateMousePosition(void);
void PrintMouseButtonStatus(void);
void UpdateMouseButtonStatus(void);
void CheckMouseButtonStatus(void);
void DrawOneButton(void);
void OnButtonClick(void);
void LabelButtons(void);
void RelabelButtons(int);
void About(void);
void InitializeMouse(void);
void Startup(void);
void LoadOne(void);
void RestrictMouse(int,int,int,int);

// cpu register structure for dos function calls.
struct REGPACK reg;
union REGS regs;


//Mouse function coding here..

int GetX(void)
{
// get mouse X position
reg.r_ax=3;
intr(51,&reg);
return(reg.r_cx);
}

int GetY(void)
{
// get mouse Y position
reg.r_ax=3;
intr(51,&reg);
return(reg.r_dx);
}


void ShowCursor(void)
{
// Turn on mouse cursor
reg.r_ax=1;
intr(51,&reg);
}

void HideCursor(void)
{
// Turn off mouse cursor.
reg.r_ax=2;
intr(51,&reg);
}

void RestrictMouse(int x1,int y1,int x2,int y2)
{
union REGS i,o;
i.x.ax=7;
i.x.cx=x1;
i.x.dx=x2;
int86(0x33,&i,&o);

i.x.ax=8;
i.x.cx=y1;
i.x.dx=y2;
int86(0x33,&i,&o);
}


void CheckMouseButtonStatus(void)
{
// gets mouse buttons pressed.

/* status=ButtonStatus();

LeftButton=0;
RightButton=0;
MiddleButton=0;

if(status==1){LeftButton=1;}
if(status==2){RightButton=1;}
if(status==3){LeftButton=1;RightButton=1;}
if(status==4){MiddleButton=1;}
if(status==5){LeftButton=1;MiddleButton=1;}
if(status==6){LeftButton=1;MiddleButton=1;}
if(status==7){LeftButton=1;RightButton=1;MiddleBut ton=1;}*/
}












int main()
{
/* request auto detection */
int gdriver = DETECT, gmode, errorcode;

/* initialize graphics mode */
initgraph(&gdriver, &gmode, "c:\\tc\\bgi");

/* read result of initialization */
errorcode = graphresult();

if (errorcode != grOk) /* an error occurred */
{
printf("Graphics error: %s\n", grapherrormsg(errorcode));
printf("Press any key to halt:");
getch();
exit(1); /* return with error code */
}

/* do some graphics */
//Heading



//green background
gsolidrectangle(640,570,0,0,deepcyan );
//text
setcolor(black);
moveto(515,130);
outtext("Control Panel");
setcolor(black);
rectangle(500,150,620,350);
rectangle(510,160,610,180);//screen
gsolidrectangle(510,160,610,180,cyan); //colour screen
//1st row button
rectangle(515,210,540,190);
rectangle(572,210,545,190);
rectangle(605,210,581,190);
moveto(525,200);
outtext("1"); //text keypad 1
moveto(555,200);
outtext("2"); //text keypad 2
moveto(590,200);
outtext("3"); //text keypad 3

//2nd row button
rectangle(515,220,540,243);
rectangle(572,220,545,243);
rectangle(580,220,605,243);
moveto(525,230);
outtext("4"); //text keypad 4
moveto(555,230);
outtext("5"); //text keypad 5
moveto(590,230);
outtext("6"); //text keypad 6

//3rd row button
rectangle(540,275,515,250);
rectangle(574,275,545,250);
rectangle(605,275,580,250);
moveto(525,260);
outtext("7"); //text keypad 7
moveto(555,260);
outtext("8"); //text keypad 8
moveto(590,260);
outtext("9"); //text keypad 9

//4th row button
rectangle(540,305,515,279);
rectangle(574,305,545,280);
rectangle(605,305,580,280);
moveto(525,290);
outtext("*"); //text keypad *
moveto(555,290);
outtext("0"); //text keypad 0
moveto(590,290);
outtext("#"); //text keypad #


//background of rectangle
gsolidrectangle(10,100,100,120,cyan);
gsolidrectangle(10,140,100,160,green);
gsolidrectangle(10,180,100,200,yellow);
gsolidrectangle(10,220,100,240,deepmagenta);
gsolidrectangle(10,260,100,280,deepgreen);
gsolidrectangle(10,300,100,320,cyan);

setcolor(deepblue);
rectangle(10,100,100,120);
rectangle(10,140,100,160);
rectangle(10,180,100,200);
rectangle(10,220,100,240);
rectangle(10,260,100,280);
rectangle(10,300,100,320);

//switch box

moveto(390,130);
outtext("Switch Box");
setcolor(black);
rectangle(490,350,350,150);
gsolidrectangle(450,160,485,190,red);//sw switch select
circle(468,175,10);
moveto(355,170);
outtext("SW Select");
//bit0 switch
gsolidrectangle(450,220,485,195,red);//bit0 switch
circle(468,207,10);
moveto(360,205);
outtext("Bit-0");
//bit1 switch
gsolidrectangle(450,250,485,225,red);//bit1 switch select
circle(468,237,10);
moveto(360,235);
outtext("Bit-1");
//bit2 switch
gsolidrectangle(450,280,485,255,red);//bit2 switch
circle(468,267,10);
moveto(360,265);
outtext("Bit-2");
gsolidrectangle(450,310,485,285,red);//bit2 switch
circle(468,297,10);
moveto(360,295);
outtext("Bit-3");

//middle button for sw swtich
circle(468,175,5);
moveto(355,170);
//middle button for bit-0
circle(468,207,5);
moveto(360,205);
//middle button for bit-1
circle(468,237,5);
moveto(360,235);
//middle button for bit-2
circle(468,267,5);
moveto(360,265);
//middle button for bit-3
circle(468,297,5);
moveto(360,295);

//Instruction box
rectangle(345,450,620,360);
moveto(360,370);
outtext("1 - Press S Start Motor");
moveto(360,390);
outtext("2 - Press T stop motor");
moveto(360,410);
outtext("3 - Press O Heater on");
moveto(360,430);
outtext("4 - Press 1 Heater off");

//Temperature box
rectangle(350,80,620,110);
gsolidrectangle(480,85,580,100,red);
moveto(360,90);
outtext("Temperature:");

//ON and OFF Switches
rectangle(350,60,620,10);
moveto(360,20);
outtext("Switches ON/OFF");
circle(361,40,5);
moveto(370,40);
outtext("ON");
circle(420,40,5);
moveto(430,40);
outtext("OFF");

//restart button
circle(500,40,5);
moveto(510,40);
outtext("Restart");

//Exit Button
rectangle(48,428,123,398);
gsolidrectangle(50,425,120,400,red);
moveto(70,410);
outtext("EXIT");


ShowCursor();
RestrictMouse(0,0,getmaxx(),getmaxy());



Here is my coding which i done so far.. and now i want to make my exit button to be close button when i click it with the mouse. any idea how i can do it and please help me
Mar 10 '07 #6
vermarajeev
180 100+
Hi,
I'll explain the steps and you follow to see if you can make it up and ready.

1) First initialize the graphics pointer.
2) Display your welcome screen (or main screen) and other stuffs you want.
3) show the mouse cursor using a function called ' show_mouse() '. The defination of this function can be like this

Expand|Select|Wrap|Line Numbers
  1. void show_mouse()
  2. {
  3.   asm{
  4.     mov ax,0x01;    /*function to show the mouse*/
  5.     int 0x33;
  6.         }
  7. }
4) Initialize a global boolean variable say 'isExitPressed'. Set this variable to false. eg. "bool isExitPressed = false"

5) Now define functions called
Expand|Select|Wrap|Line Numbers
  1. "check_area_of_mouse()",  "mouse_button_press()"
with appropriate arguments.

6) Write your logic something like this. This is just a sample.
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.     show_mouse();
  4.     while (!isExitPressed)
  5.    {
  6.           if (mouse_button_press())
  7.     check_area_of_mouse();
  8.    }
  9.    closegraph();
  10. }
  11. int mouse_button_press()
  12. {
  13.    union REGS in,out;
  14.    in.x.ax=0x03;         /*interrupt to  check the click of the mouse*/
  15.    int86(0x33,&in,&out);
  16.    return out.h.bl & 0x01;
  17. }
  18.  
In check_area_of_mouse() function check if exit button was pressed. If Exit was pressed then set isExitPressed = true;

Hope this helps.
Mar 10 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alex | last post by:
I am trying to write an Exit module for the Certification server in VB.NET and I cant get the module to be recognised by the Certification MMC snap in. Its function is to capture Serial Numbers of...
32
by: Protoman | last post by:
I have a function that calculates the mean of the some numbers; I need it to accept any number of parameters (one needs to be the number of the other parameters) Can you help me out here? Here's...
7
by: Darklight | last post by:
if the exit() function is contained in stdlid.h why if i remove the above header file the exit function still works and i can still compile program without any error messages using cc file.c if i...
17
by: jwaixs | last post by:
Hello, I was wondering, what's the difference between exit and return in the main() function? For me they both look the same, or aren't they? And if they aren't, which should I use in which...
6
by: orekin | last post by:
Hi There I have been trying to come to grips with Application.Run(), Application.Exit() and the Message Pump and I would really appreciate some feedback on the following questions .. There are...
3
by: darrel | last post by:
This might be a really dumb question, but when should/shouldn't one use the exit function command? If I have this: function() if something then do this return that else
20
by: lovecreatesbeauty | last post by:
Hello experts, Is the following code snippet legal? If it is, how can exit() do the keyword return a favor and give a return value to the main function? Can a function call (or only this...
16
by: Laurent Deniau | last post by:
I would like to know if the use of the pointer ref in the function cleanup() below is valid or if something in the norm prevents this kind of cross-reference during exit(). I haven't seen anything...
11
by: =?Utf-8?B?U3RldmVEQjE=?= | last post by:
Hi all. I'm using VS 2008 Express C++. I created a console application back in 1999, and updated it for VC++ 6.0 in 2001. I've updated again this past month, and have found enough differences...
39
by: mathieu | last post by:
Hi there, I am trying to reuse a piece of code that was designed as an application. The code is covered with 'exit' calls. I would like to reuse it as a library. For that I renamed the 'main'...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.