Welcome
Welcome to the forums of AntiRTFM's Absolute N00b Spoonfeed C++ Tutorials!

You are currently viewing our boards as a guest, which gives you limited access to view most discussions and access our other features. By joining our free community, you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content, and access many other special features. Registration is fast, simple, and absolutely free, so please, <a href="/profile.php?mode=register">join our community today</a>!

SELECT CHARACTER INSERTION POINT !!!!!

Display your little helpful snippets of code that may help us all get something done

SELECT CHARACTER INSERTION POINT !!!!!

Postby glinka57 on Tue Mar 24, 2009 6:03 pm

well first off, antiRTFM 'I KNOW' you will eventually get to this in the videos, but for us who participate in this forum will only have the head start' I guess you could say.. so the point is I'm NOT jumping the gun XD. this is just way cool

after searching around on if there were ways to 'specify' the insertion point of the cursor (with pricision) I stumbled upon the gotoxy/SetConsoleCursorPosition function or class thing, lol, sorry dont know what to call it.. ,
here it is and what it does as best I understand:

It uses a CLASS called "COORD" found in the <windows.h> header, so you'll have to #include it.

Out in the global scope create the function below. I'll add comments to it

Code: Select all
void gotoxy ( short x, short y ) 
{                                         
  COORD coord = {x, y}; 
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
}

-----------------------------------------------------------------------------------------------------------------------
                                                I'll try to define what it does:
-----------------------------------------------------------------------------------------------------------------------
void gotoxy ( short x, short y )
/*these are going to be the x and y coordinates of the cursor, assuming one character occupies 'one' grid location.
   so your console screen is basically a black grid (with the lines imvisible). I guess its short because console screens dont   
   get pretty big. the top most leftmost point (or square) of the console window is (0,0) and x increases horizontally and y
   increases vertically.*/
{                                       
  COORD coord = {x, y}; 
/* Here they summon the class COORD and create an instance of it that they chose to call 'coord'.
    then coord is assigned the values x and y. (btw dont mess with any of the syntax or names unless you are uber pro)
*/   
 
  SetConsoleCursorPosition ( GetStdHandle ( STD_OUTPUT_HANDLE ), coord );
/*
   so here im assuming the header window.h declared a function called SetConsoleCursorPosition (blah blah);
   and now we're summoning it.
*/
}



-----------------------------------------------------------------------------------------------------------------------
How to Use it
-----------------------------------------------------------------------------------------------------------------------

As you could see, to use it in your function all you need to do is
-#include <windows.h>
-copy and past the function " void gotoxy ( short x, short y ); " to the code. preferably free (in the global scope)
-then call that function whenever you want to set the cursor position. making sure you feed it the x , y values you want

I looked around for a long time and all mentions of this was a bit technichal and not straight forward, so that why I take the laborious time to add it to our archive here XD, in such detail. (only need to do it once LOL)
So now the knowledge is yours o mighty noob. I can see 'so many' uses for this. lol

Some of you know I'm working on an "ASCII APARATUS" for generating text graphics, well this right here, will revolutionize it muahahaha. check the full programs section if I make an update to it soon.

I dont have time to proof read this for typos. so tough and sorry if ther are eny
User avatar
glinka57
 
Posts: 158
Joined: Fri Feb 27, 2009 7:32 pm

Re: SELECT CHARACTER INSERTION POINT !!!!!

Postby antiRTFM on Tue Mar 24, 2009 6:16 pm

nice job digging glinka57!

you remind me of my old "Win32ConsoleManager" class i made way back... I had spacing and allignment, coloring, positioning, etc. but i wouldnt wanna take the fun out of your project so i dont think you'd want me to just spill the code out eh
User avatar
antiRTFM
Administrator
 
Posts: 462
Joined: Sun Apr 13, 2008 9:10 am

Re: SELECT CHARACTER INSERTION POINT !!!!!

Postby glinka57 on Tue Mar 24, 2009 6:35 pm

exactly LOL!, but dont worry, our technicians over here at the Glinka facilities are working round the clock on
hammering away on the Aparatus :lol:
User avatar
glinka57
 
Posts: 158
Joined: Fri Feb 27, 2009 7:32 pm

Re: SELECT CHARACTER INSERTION POINT !!!!!

Postby antiRTFM on Tue Mar 24, 2009 7:32 pm

you lulz me XD
User avatar
antiRTFM
Administrator
 
Posts: 462
Joined: Sun Apr 13, 2008 9:10 am


Return to Snippets

Who is online

Users browsing this forum: No registered users and 0 guests