By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,918 Members | 2,279 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,918 IT Pros & Developers. It's quick & easy.

error coding please help

P: 32
well i have my mouse working and now im trying to make my exit button working when the mouse clicked onto exit button and it will exit the application


here is my coding for the mouse function to exit the application

.................................................. .................................................. ..............

//The function getmousepos gets the position of the mouse alongwith the mouse button state. Like which
//button is pressed 1,2. If button =1 then it is left mouse and if it is 2 then right mouse button click.
Expand|Select|Wrap|Line Numbers
  1. void getmousepos(int *button,int *x,int *y)
  2.     {
  3.     char *ss;
  4.     union REGS i,o;
  5.     i.x.ax=3;
  6.     int86(0x33,&i,&o);
  7.     *button=o.x.bx;
  8.     *x=o.x.cx;
  9.     *y=o.x.dx;
  10.     }
  11.  
  12.  
  13.  
  14. //The below loop executes until anything is pressed and then getmousepos is called to get the position of
  15. //the mouse and if it falls in between x>=70 && x<=100 && y>=410 && y<=420 then exit from the program.
  16. //void thisismycode()
  17. {
  18.      while(!kbhit())
  19.      {
  20.       getmousepos(&button,&x,&y);
  21.       if((button&1)==1)
  22.       {
  23.         getmousepos(&button,& x,& y);
  24.         if(x>=70 && x<=100 && y>=410 && y<=420)
  25.          exit(0);
  26.       }
  27.      }
  28.  
  29.  }
  30.  
  31.  
.................................................. .................................................. ............

My error message when i complile


undefined symbol 'button'
undefined symbol 'x'
undefined symbol 'y'
.................................................. .................................................. .............

what have i done.. have i missed something there..
Mar 20 '07 #1
Share this Question
Share on Google+
8 Replies


dmjpro
100+
P: 2,476
where u define these variables ??????
Mar 20 '07 #2

P: 32
where u define these variables ??????
how you mean where i define these variables???
well im using old version of turbo c
Mar 20 '07 #3

Expert 100+
P: 1,510
how you mean where i define these variables???
well im using old version of turbo c
need to define button, x and y and initialise the mouse - try this as a test program
Expand|Select|Wrap|Line Numbers
  1. int main()
  2. {
  3.      int button, x,y;                        // << define variables
  4.     union REGS registers;                  /* variable to hold 8086 registers */
  5.  
  6.     registers.x.ax = 0;                          /* reset the Microsoft mouse */
  7.     int86(0x33, &registers, &registers);
  8.      while(!kbhit())
  9.      {
  10.       getmousepos(&button,&x,&y);
  11.       printf("%d %d %d \n", button, x, y);
  12.       if((button&1)==1)
  13.       {
  14.         getmousepos(&button,& x,& y);
  15.         if(x>=70 && x<=100 && y>=410 && y<=420)
  16.          exit(0);
  17.       }
  18.      }
  19.  
  20.  }
  21.  
Mar 20 '07 #4

P: 32
Expand|Select|Wrap|Line Numbers
  1. /* list the include file */
  2. /*#include <direct.h>*/
  3. #include <conio.h>
  4. #include <stdio.h>
  5. #include <stdlib.h>
  6. #include <math.h>
  7. #include <string.h>
  8. #include <time.h>
  9. #include <ctype.h>
  10. #include <dos.h>
  11. #include <graphics.h>
  12.  
  13.  
  14. /* check the colours !!!! */
  15. int    black     =    0;
  16. int    deepblue =    1;
  17. int    deepgreen =    2;
  18. int    deepcyan    =     3;
  19. int    deepred    =    4;
  20. int    deepmagenta=    5;
  21. int    brown        =    6;
  22. int    gray        =    7;
  23. int    blue        =    8;
  24. int    green     =    10;
  25. int    cyan        =    11;
  26. int    red        =    12;
  27. int    magenta    =    13;
  28. int    yellow    =    14;
  29. int    white     =    15;
  30.  
  31. int yline0= 0 ;   /* position of a Y line */
  32. int yline1= 20 ;  /* position of a Y line */
  33. int yline2= 40 ;   /* position of a Y line */
  34. int yline3= 60 ;   /* position of a Y line */
  35. int yline4= 80 ;   /* position of a Y line */
  36. int yline5= 100 ;  /* position of a Y line */
  37. int yline6= 120 ;  /* position of a Y line */
  38. int yline7= 140;  /* position of a Y line */
  39. int yline8= 160;  /* position of a Y line */
  40. int yline9= 180;  /* position of a Y line */
  41. int yline10 = 200 ;  /* position of a Y line */
  42. int yline11 = 220 ;  /* position of a Y line */
  43. int yline12 = 240 ;  /* position of a Y line */
  44. int yline13 = 260 ;   /* position of a Y line */
  45. int yline14 = 280 ;   /* position of a Y line */
  46. int yline15 = 300 ;   /* position of a Y line */
  47. int yline16 = 320 ;   /* position of a Y line */
  48. int yline17 = 340;  /* position of a Y line */
  49. int yline18 = 360 ;   /* position of a Y line */
  50. int yline19 = 380 ;   /* position of a Y line */
  51. int yline20 = 400 ;   /* position of a Y line */
  52. int yline21 = 420 ;   /* position of a Y line */
  53. int yline22 = 440 ;   /* position of a Y line */
  54. int yline23 = 460 ;   /* position of a Y line */
  55. void heading(char *string);
  56. void centreline(char *string);
  57. void gcls(void) ;
  58. void gsolidrectangle(int x1, int y1, int x2, int y2,int col);
  59.  
  60. //mouse int function
  61. int GetX(void);
  62. int GetY(void);
  63. int GetKey(void);
  64. void ShowCursor(void);
  65. void HideCursor(void);
  66. int ButtonStatus(void);
  67. void SetMouseMode(int);
  68. void PrintMousePosition(void);
  69. void UpdateMousePosition(void);
  70. void PrintMouseButtonStatus(void);
  71. void UpdateMouseButtonStatus(void);
  72. void CheckMouseButtonStatus(void);
  73. void DrawOneButton(void);
  74. void OnButtonClick(void);
  75. void LabelButtons(void);
  76. void RelabelButtons(int);
  77. void About(void);
  78. void InitializeMouse(void);
  79. void Startup(void);
  80. void LoadOne(void);
  81. void RestrictMouse(int,int,int,int);
  82.  
  83. // cpu register structure for dos function calls.
  84. struct REGPACK reg;
  85. union REGS regs;
  86.  
  87.  
  88. //Mouse function coding here..
  89.  
  90. int GetX(void)
  91. {
  92. // get mouse X position
  93.     reg.r_ax=3;
  94.     intr(51,&reg);
  95.     return(reg.r_cx);
  96. }
  97.  
  98. int GetY(void)
  99. {
  100. // get mouse Y position
  101.     reg.r_ax=3;
  102.     intr(51,&reg);
  103.     return(reg.r_dx);
  104. }
  105.  
  106.  
  107. void ShowCursor(void)
  108. {
  109. // Turn on mouse cursor
  110.     reg.r_ax=1;
  111.     intr(51,&reg);
  112. }
  113.  
  114. void HideCursor(void)
  115. {
  116. // Turn off mouse cursor.
  117.     reg.r_ax=2;
  118.     intr(51,&reg);
  119. }
  120.  
  121. void RestrictMouse(int x1,int y1,int x2,int y2)
  122. {
  123. union REGS i,o;
  124. i.x.ax=7;
  125. i.x.cx=x1;
  126. i.x.dx=x2;
  127. int86(0x33,&i,&o);
  128.  
  129. i.x.ax=8;
  130. i.x.cx=y1;
  131. i.x.dx=y2;
  132. int86(0x33,&i,&o);
  133. }
  134. void getmousepos(int *button,int *x,int *y)
  135.     {
  136.     char *ss;
  137.     union REGS i,o;
  138.     i.x.ax=3;
  139.     int86(0x33,&i,&o);
  140.     *button=o.x.bx;
  141.     *x=o.x.cx;
  142.     *y=o.x.dx;
  143.     }
  144.  
  145. void CheckMouseButtonStatus(void)
  146. {
  147. // gets mouse buttons pressed.
  148.  
  149. /*    status=ButtonStatus();
  150.  
  151.     LeftButton=0;
  152.     RightButton=0;
  153.     MiddleButton=0;
  154.  
  155.     if(status==1){LeftButton=1;}
  156.     if(status==2){RightButton=1;}
  157.     if(status==3){LeftButton=1;RightButton=1;}
  158.     if(status==4){MiddleButton=1;}
  159.     if(status==5){LeftButton=1;MiddleButton=1;}
  160.     if(status==6){LeftButton=1;MiddleButton=1;}
  161.     if(status==7){LeftButton=1;RightButton=1;MiddleButton=1;}*/
  162. }
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175. int main()
  176.     {
  177.     /* request auto detection */
  178.     int gdriver = DETECT, gmode, errorcode,button=1,x,y;
  179.  
  180.     /* initialize graphics mode */
  181.     initgraph(&gdriver, &gmode, "c:\\turboc");
  182.  
  183.     /* read result of initialization */
  184.     errorcode = graphresult();
  185.  
  186.     if (errorcode != grOk)  /* an error occurred */
  187.         {
  188.         printf("Graphics error: %s\n", grapherrormsg(errorcode));
  189.         printf("Press any key to halt:");
  190.         getch();
  191.         exit(1);             /* return with error code */
  192.         }
  193.  
  194.     /* do some graphics */
  195.     //Heading
  196.  
  197.  
  198.  
  199.     //green background
  200.         gsolidrectangle(640,570,0,0,deepcyan );
  201.         //text
  202.         setcolor(black);
  203.         moveto(515,130);
  204.         outtext("Control Panel");
  205.         setcolor(black);
  206.         rectangle(500,150,620,350);
  207.         rectangle(510,160,610,180);//screen
  208.         gsolidrectangle(510,160,610,180,cyan); //colour screen
  209.         //1st row button
  210.         rectangle(515,210,540,190);
  211.         rectangle(572,210,545,190);
  212.         rectangle(605,210,581,190);
  213.         moveto(525,200);
  214.         outtext("1");    //text keypad 1
  215.         moveto(555,200);
  216.         outtext("2");    //text keypad 2
  217.         moveto(590,200);
  218.         outtext("3");    //text keypad 3
  219.  
  220.         //2nd row button
  221.         rectangle(515,220,540,243);
  222.         rectangle(572,220,545,243);
  223.         rectangle(580,220,605,243);
  224.         moveto(525,230);
  225.         outtext("4");     //text keypad 4
  226.         moveto(555,230);
  227.         outtext("5");   //text keypad 5
  228.         moveto(590,230);
  229.         outtext("6");    //text keypad 6
  230.  
  231.         //3rd row button
  232.         rectangle(540,275,515,250);
  233.         rectangle(574,275,545,250);
  234.         rectangle(605,275,580,250);
  235.         moveto(525,260);
  236.         outtext("7");      //text keypad 7
  237.         moveto(555,260);
  238.         outtext("8");   //text keypad 8
  239.         moveto(590,260);
  240.         outtext("9");   //text keypad 9
  241.  
  242.         //4th row button
  243.         rectangle(540,305,515,279);
  244.         rectangle(574,305,545,280);
  245.         rectangle(605,305,580,280);
  246.         moveto(525,290);
  247.         outtext("*");      //text keypad *
  248.         moveto(555,290);
  249.         outtext("0");   //text keypad 0
  250.         moveto(590,290);
  251.         outtext("#");   //text keypad #
  252.  
  253.  
  254.         //background of rectangle
  255.         gsolidrectangle(10,100,100,120,cyan);
  256.         gsolidrectangle(10,140,100,160,green);
  257.         gsolidrectangle(10,180,100,200,yellow);
  258.         gsolidrectangle(10,220,100,240,deepmagenta);
  259.         gsolidrectangle(10,260,100,280,deepgreen);
  260.         gsolidrectangle(10,300,100,320,cyan);
  261.  
  262.         setcolor(deepblue);
  263.         rectangle(10,100,100,120);
  264.         rectangle(10,140,100,160);
  265.         rectangle(10,180,100,200);
  266.         rectangle(10,220,100,240);
  267.         rectangle(10,260,100,280);
  268.         rectangle(10,300,100,320);
  269.  
  270.         //switch box
  271.  
  272.             moveto(390,130);
  273.         outtext("Switch Box");
  274.         setcolor(black);
  275.         rectangle(490,350,350,150);
  276.         gsolidrectangle(450,160,485,190,red);//sw switch select
  277.         circle(468,175,10);
  278.         moveto(355,170);
  279.                 outtext("SW Select");
  280.         //bit0 switch
  281.         gsolidrectangle(450,220,485,195,red);//bit0 switch
  282.         circle(468,207,10);
  283.         moveto(360,205);
  284.         outtext("Bit-0");
  285.         //bit1 switch
  286.         gsolidrectangle(450,250,485,225,red);//bit1 switch select
  287.         circle(468,237,10);
  288.         moveto(360,235);
  289.                 outtext("Bit-1");
  290.         //bit2 switch
  291.         gsolidrectangle(450,280,485,255,red);//bit2 switch
  292.         circle(468,267,10);
  293.         moveto(360,265);
  294.                 outtext("Bit-2");
  295.         gsolidrectangle(450,310,485,285,red);//bit2 switch
  296.         circle(468,297,10);
  297.         moveto(360,295);
  298.         outtext("Bit-3");
  299.  
  300.         //middle button for sw swtich
  301.         circle(468,175,5);
  302.         moveto(355,170);
  303.         //middle button for bit-0
  304.                 circle(468,207,5);
  305.         moveto(360,205);
  306.         //middle button for bit-1
  307.         circle(468,237,5);
  308.         moveto(360,235);
  309.         //middle button for bit-2
  310.         circle(468,267,5);
  311.         moveto(360,265);
  312.         //middle button for bit-3
  313.         circle(468,297,5);
  314.         moveto(360,295);
  315.  
  316.         //Instruction box
  317.         rectangle(345,450,620,360);
  318.         moveto(360,370);
  319.         outtext("1 - Press S Start Motor");
  320.         moveto(360,390);
  321.         outtext("2 - Press T stop motor");
  322.         moveto(360,410);
  323.         outtext("3 - Press O Heater on");
  324.         moveto(360,430);
  325.         outtext("4 - Press 1 Heater off");
  326.  
  327.         //Temperature box
  328.         rectangle(350,80,620,110);
  329.         gsolidrectangle(480,85,580,100,red);
  330.         moveto(360,90);
  331.         outtext("Temperature:");
  332.  
  333.         //ON and OFF Switches
  334.         rectangle(350,60,620,10);
  335.         moveto(360,20);
  336.         outtext("Switches ON/OFF");
  337.         circle(361,40,5);
  338.         moveto(370,40);
  339.         outtext("ON");
  340.         circle(420,40,5);
  341.         moveto(430,40);
  342.         outtext("OFF");
  343.  
  344.         //restart button
  345.         circle(500,40,5);
  346.         moveto(510,40);
  347.         outtext("Restart");
  348.  
  349.         //Exit Button
  350.         rectangle(48,428,123,398);
  351.         gsolidrectangle(50,425,120,400,red);
  352.         moveto(70,410);
  353.         outtext("EXIT");
  354.  
  355.  
  356.         ShowCursor();
  357.         RestrictMouse(0,0,getmaxx(),getmaxy());
  358. int main()
  359. {
  360.      int button, x,y;                        // << define variables
  361.     union REGS registers;                  /* variable to hold 8086 registers */
  362.  
  363.     registers.x.ax = 0;                          /* reset the Microsoft mouse */
  364.     int86(0x33, &registers, &registers);
  365.      while(!kbhit())
  366.      {
  367.       getmousepos(&button,&x,&y);
  368.       printf("%d %d %d \n", button, x, y);
  369.       if((button&1)==1)
  370.       {
  371.         getmousepos(&button,& x,& y);
  372.         if(x>=70 && x<=100 && y>=410 && y<=420)
  373.          exit(0);
  374.       }
  375.      }
  376.  
  377.  }
  378.  
  379. void heading(char *string)
  380.     {
  381.     gcls() ;
  382.     moveto(320 - (strlen(string) * 8) , yline0); /* centre text */
  383.     settextstyle(0,0,2);
  384.     outtext(string) ; /* print text */
  385.     settextstyle(0,0,1);
  386.     }
  387.  
  388. void centreline(char *string)
  389.     {
  390.     int length,start ;
  391.     start = ((80 - strlen(string))/2) * 8 ;
  392.     length = strlen(string) *9 ;
  393.     rectangle(start-6,yline11 - 10, start + length + 16 , yline12 + 10);
  394.     rectangle(start-4,yline11 - 8, start + length + 14 , yline12 + 8);
  395.     moveto(start + 10, yline11); /* centre text */
  396.     outtext(string) ; /* print text */
  397.     }
  398.  
  399. /* clear the screen */
  400. void gcls(void)
  401.     {
  402.     gsolidrectangle(0,0,639,479,black);
  403.     }
  404.  
  405. /* draw solid rectangle */
  406. void gsolidrectangle(int x1, int y1, int x2, int y2,int col)
  407.     {
  408.     int poly[8],tcol;
  409.     tcol = getcolor();
  410.     poly[0] = poly[6] = x1;          /* 1st vertex */
  411.     poly[1] = poly[3] = y1;
  412.     poly[2] = poly[4] = x2;          /* 1st vertex */
  413.     poly[7] = poly[5] = y2;
  414.     setfillstyle(SOLID_FILL,col);
  415.     setcolor(col);
  416.     fillpoly(4, poly);
  417.     setcolor(tcol);
  418.     }
  419.  
Mar 20 '07 #5

P: 32
hi.

I have managed to correct from your code to mine.. some how i got an error saying

please check above thanks

Declaration is not allowed here
Declaration syntax error
Declaration missing ;
function should return a value
Mar 20 '07 #6

DeMan
100+
P: 1,806
I can see two implementations of main. The second one comes ion the middle of the first, and I suspect the parentheses are mixed up as a result. So: get rid of the second "int main()" and then make sure all your parentheses line up as required...
Mar 20 '07 #7

P: 32
I can see two implementations of main. The second one comes ion the middle of the first, and I suspect the parentheses are mixed up as a result. So: get rid of the second "int main()" and then make sure all your parentheses line up as required...
i have managed to get rid of the main int() in the middle.. still same error message

please help any1
Mar 20 '07 #8

DeMan
100+
P: 1,806
Might like to move the iont and union declarations (where the int main() originally was) up to the top of teh method.....
Mar 21 '07 #9

Post your reply

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