Input a string in graphics mode?

This is a discussion on Input a string in graphics mode? within the C++ Programming forums, part of the General Programming Boards category; I'm not writing a specific program using this at the moment, but I'm just trying to build up my knowledge ...

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    11

    Question Input a string in graphics mode?

    I'm not writing a specific program using this at the moment, but I'm just trying to build up my knowledge database before jumping into game programming and such. My question is:

    How would I input a string of more than one character in graphics mode?

    I know cin and gets() works in graphics mode, but it displays dos style text and inputs over the 80x25 text mode grid rather than at specific X Y coordinates. I considered looping getch() until the enter key is pressed and having each key printed out using outtextxy() then formatting them into one string, but that seems very unnecessary. If anyone knows a better way, I would appreciate any form of a response.

    (unless that response is calling me stupid )
    C:\DOS\
    C:\DOS\RUN\
    \RUN\DOS\RUN\

  2. #2
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    I wrote this code... this works on BGI..

    Code:
    char* gettextxy(int x1,int y1,byte colorback = 0,
    		byte colorfont = 15, byte limit = 0)
    {
     byte x=0;
     int i=0;
     char in[2];
     in[0]=' ';
     in[1]='\0';
     char *texto;
    
     int originalcolor = getcolor();
    
     while(*in!=(char)13)
     {
       in[0]=getch();
       if(in[0]==(char)13) break;
        else
         if(in[0]==(char)8)
         {
          x--;
          i-=7;
          setcolor(colorback);
          in[0]=texto[x];
          outtextxy(x1+i,y1,in);
         }
        else
        {
         if ((x < limit) || (limit == 0))
           {
    	setcolor(colorfont);
    	outtextxy(x1+i,y1,in);
    	i+=7;
    	texto[x]=in[0];
    	x++;
           }
        }
     }
     setcolor(originalcolor);
     texto[x]='\0';
     return(texto);
    }
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  3. #3
    Registered User madsmile's Avatar
    Join Date
    Feb 2002
    Posts
    26
    I forgot this..

    typedef unsigned char byte;

    this is the type declaration for byte...
    MADSmile
    ICQ #3653692
    (i'm running Borlad C++ Ver 3.1 under MSDOS)

  4. #4
    Registered User
    Join Date
    Mar 2002
    Posts
    11
    Yeah I figured that last part out myself. Thanks for the code, that worked.
    C:\DOS\
    C:\DOS\RUN\
    \RUN\DOS\RUN\

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Inheritance Hierarchy for a Package class
    By twickre in forum C++ Programming
    Replies: 7
    Last Post: 12-08-2007, 04:13 PM
  2. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  3. Something is wrong with this menu...
    By DarkViper in forum Windows Programming
    Replies: 2
    Last Post: 12-14-2002, 11:06 PM
  4. Classes inheretance problem...
    By NANO in forum C++ Programming
    Replies: 12
    Last Post: 12-09-2002, 03:23 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21