Get the current position and return it as a structure.
#include <graph.h>
struct _xycoord __far _getcurrentposition( void );
struct _wxycoord __far _getcurrentposition_w( void );
The _getcurrentposition functions return the coordinates of the current graphics output position. The _getcurrentposition function returns the position as an _xycoord structure, defined in GRAPH.H.
The _xycoord structure contains the following elements:
Element | Description |
short xcoord | x coordinate |
short ycoord | y coordinate |
The _getcurrentposition_w function returns the position as a _wxycoord structure, defined in GRAPH.H.
The _wxycoord structure contains the following elements:
Element | Description |
double wx | window x coordinate |
double wy | window y coordinate |
The current position can be changed by the _lineto, _moveto, and _outgtext functions.
The default position, set by _setvideomode, _setvideomoderows, or _setviewport, is the center of the viewport.
Only graphics output starts at the current position; these functions do not affect text output, which begins at the current text position. (See _settextposition for more information.)
The _getcurrentposition functions return the coordinates of the current graphics output position. There is no error return.
Standards:None
16-Bit:DOS
32-Bit:None
_grstatus, _lineto functions, _moveto functions, _outgtext
/* GCURPOS.C: This program sets a random current location, then gets that
* location with _getcurrentposition.
*/
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <graph.h>
char buffer[255];
void main( void )
{
struct _videoconfig vc;
struct _xycoord position;
/* Find a valid graphics mode. */
if( !_setvideomode( _MAXRESMODE ) )
exit( 1 );
_getvideoconfig( &vc );
/* Move to random location and report that location. */
_moveto( rand() % vc.numxpixels, rand() % vc.numypixels );
position = _getcurrentposition();
sprintf( buffer, "x = %d, y = %d", position.xcoord, position.ycoord );
_settextposition( 1, 1 );
_outtext( buffer );
_getch();
_setvideomode( _DEFAULTMODE );
}