home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / mslang / cursor / cursor.c next >
C/C++ Source or Header  |  1994-03-18  |  11KB  |  194 lines

  1. #include <conio.h>
  2. #include "cursor.h"
  3.  
  4.  /*************************************************************************\
  5. |                                                                           |
  6. |  Programmer     : Omer YALHI                                              |
  7. |  CompuServe     : 71501,243                                               |
  8. |  America OnLine : Falcon Men                                              |
  9. |  Internet       : camel@acs.bu.edu                                        |
  10. |  Type           : Freeware                                                |
  11. |  Purpose        : Some cursor routines                                    |
  12. |  Version        : 1.0                                                     |
  13. |  Last Modified  : March 18'94                                             |
  14. |  Compiler Used  : Microsoft Visual C++ 1.0                                |
  15. |                                                                           |
  16.  \*************************************************************************/
  17.  
  18.  /*************************************************************************\
  19. |                              FUNCTIONS                                    |
  20.  \*************************************************************************/  
  21.  
  22.  /*************************************************************************\
  23. |                                                                           |
  24. | void eeol();                                                              |
  25. |___________________________________________________________________________|
  26. |                                                                           |
  27. | Erases the line from current cursor position to the end of line           |
  28. | Uses whatever the current attribute is.  Doesn't change the               |
  29. | cursor position.                                                          |
  30. |___________________________________________________________________________|
  31. |                                                                           |
  32. | Inputs  : None                                                            |
  33. | Returns : None                                                            |
  34. |                                                                           |
  35.  \*************************************************************************/
  36. void eeol()
  37. {
  38.     int    x = wherex();                /* get current col */
  39.     int    y = wherey();                /* get current row */
  40.     int    xOld = x;                    /* save current col */
  41.     int    yOld = y;                    /* save current row */
  42.     int    styleOld = getcursor();        /* save cursor style */
  43.     
  44.     showcursor(NOCURSOR);            /* hide cursor */
  45.     for(; x < 80; x++)    {            /* start from current location */
  46.         gotoxy(x, y);                /*   till the end of line */
  47.         _cprintf(" ");                /*   and erase the character */
  48.     }
  49.     showcursor(styleOld);            /* show cursor as it was before */
  50.     gotoxy(xOld, yOld);                /* place cursor where it was before */
  51. }
  52.  
  53.  /*************************************************************************\
  54. |                                                                           |
  55. | void gotoxy(int x, int y);                                                |
  56. |___________________________________________________________________________|
  57. |                                                                           |
  58. | Places cursor to the specified postion.  Uses page 0.                     |
  59. |___________________________________________________________________________|
  60. |                                                                           |
  61. | Inputs  : int x -> column for cursor (lowest = 1)                         |
  62. | Returns : int y -> row for cursor (lowest = 1)                            |
  63. |                                                                           |
  64.  \*************************************************************************/
  65. void gotoxy(int x, int y)
  66. {
  67.     x--;                            /* service uses base 0 so decrement */
  68.     y--;                            /* service uses base 0 so decrement */
  69.     __asm    {
  70.         mov    ah, 2                    /* service no 2 */
  71.         mov    bh, 0                    /* use page number 0 */
  72.         mov    cx, y                    /* y is in cl now, don't care what ch is */
  73.         mov    dx, x                   /* put col info in dx.  x is in dl now */
  74.         mov    dh, cl                    /* put row info in dh.  dx has row and col info */
  75.         int    10h                        /* invoke interrupt routine */
  76.     }
  77. }
  78.  
  79.  /*************************************************************************\
  80. |                                                                           |
  81. | int wherey();                                                             |
  82. |___________________________________________________________________________|
  83. |                                                                           |
  84. | Returns the current row position of the cursor.  Uses page number 0.      |
  85. |___________________________________________________________________________|
  86. |                                                                           |
  87. | Inputs  : None                                                            |
  88. | Returns : current row postion of the cursor                               |
  89. |                                                                           |
  90.  \*************************************************************************/
  91. int wherey()
  92. {
  93.     int    y;                            /* value to be returned */
  94.     
  95.     __asm    {
  96.         mov ah, 3                    /* service no 3 */
  97.         mov bh, 0                    /* use page number 0 */
  98.         int    10h                     /* invoke interrupt routine */
  99.         mov    dl, dh                  /* dh has row information, so put in loe byte */
  100.         xor dh, dh                  /* we don't need dh */
  101.         inc    dl                      /* service uses base 0, so increment */
  102.         mov    y, dx                    /* save row information y */
  103.     }
  104.     return    y;                        /* return row number */
  105. }
  106.  
  107.  /*************************************************************************\
  108. |                                                                           |
  109. | int wherex();                                                             |
  110. |___________________________________________________________________________|
  111. |                                                                           |
  112. | Returns the current column position of the cursor.  Uses page number 0.   |
  113. |___________________________________________________________________________|
  114. |                                                                           |
  115. | Inputs  : None                                                            |
  116. | Returns : current column postion of the cursor                            |
  117. |                                                                           |
  118.  \*************************************************************************/
  119. int wherex()
  120. {
  121.     int    x;                            /* value to be returned */
  122.     
  123.     __asm    {
  124.         mov ah, 3                    /* service no 3 */
  125.         mov bh, 0                    /* use page number 0 */
  126.         int    10h                     /* invoke interrupt routine */
  127.         xor dh, dh                  /* col info is in dl, we don't need dh */
  128.         inc    dl                      /* service uses base 0, so increment */
  129.         mov    x, dx                    /* save col information in x */
  130.     }
  131.     return    x;                        /* return column number */
  132. }
  133.  
  134.  /*************************************************************************\
  135. |                                                                           |
  136. | void showcursor(int style);                                               |
  137. |___________________________________________________________________________|
  138. |                                                                           |
  139. | Changes the shape of the cursor according to the style.                   |
  140. |___________________________________________________________________________|
  141. |                                                                           |
  142. | Inputs  : int style -> style to be used.  Available styles defined in     |
  143. |                        cursor.h are :                                     |
  144. |                                                                           |
  145. |                        NOCURSOR                                           |
  146. |                        NORMALCURSOR                                       |
  147. |                        BLOCKCURSOR                                        |
  148. |                                                                           |
  149. | Returns : None                                                            |
  150. |                                                                           |
  151.  \*************************************************************************/
  152. void showcursor(int style)
  153. {
  154.     __asm    {
  155.         mov    ah, 1                    /* service no 1 */
  156.         mov cx, style                /* put style in cx */
  157.         int    10h                        /* invoke interrupt routine */
  158.     }
  159. }
  160.  
  161.  /*************************************************************************\
  162. |                                                                           |
  163. | int getcursor();                                                          |
  164. |___________________________________________________________________________|
  165. |                                                                           |
  166. | Returns the style of the cursor.                                          |
  167. |___________________________________________________________________________|
  168. |                                                                           |
  169. | Inputs  : None                                                            |
  170. |                                                                           |
  171. | Returns : style -> Available styles defined in cursor.h are :             |
  172. |                                                                           |
  173. |                        NOCURSOR                                           |
  174. |                        NORMALCURSOR                                       |
  175. |                        BLOCKCURSOR                                        |
  176. |                                                                           |
  177. |                    Note that the returned value might not be one of the   |
  178. |                    defined styles.                                        |
  179. |                                                                           |
  180.  \*************************************************************************/
  181. int getcursor()
  182. {
  183.     int    style;                        /* value to be returned */
  184.     
  185.     __asm    {
  186.         mov    ah, 3                    /* service no 3 */
  187.         mov    bh, 0                    /* use page number 0 */
  188.         int    10h                        /* invoke interrupt routine */
  189.         mov    style, cx                /* put info in style */
  190.     }    
  191.     return style;                    /* return style */
  192. }
  193.  
  194.