Results 1 to 13 of 13

Thread: Locating the cursor at a specific coordinate

  1. #1
    Sc0rp
    Guest

    Talking Locating the cursor at a specific coordinate

    How do I write text in a specific place on the screen in a console app?

  2. #2
    Sc0rp
    Guest
    I know gotoxy() doesn't exist in VC++, but I can't seem to get graphics.h anywhere, so is there any way to bypass this and not use gotoxy()?

  3. #3
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Try this:

    Code:
    #include <windows.h>
    #include <iostream.h>
    COORD crd;
    HWND hd;
    int main()
    {
    	int x;
    	crd.X = 50;
        crd.Y = 50;
    
    	hd = GetConsoleWindow();
    	SetConsoleCursorPosition(hd, crd);
    
    	cout<<"This text is on different location";
    	cin>>x;
    	return 0;
    }

    I does not work for me because the compiler is not recognizing "GetConsoleWindow". But Platform SDK has the function to get a handle to the console.

    Try this and see if it works!
    Baaaaaaaaah

  4. #4
    Sc0rp
    Guest
    Thanks, but my VC++6 doesn't recognize this function either.

    Any other ideas?

  5. #5
    Zaei
    Guest
    Code:
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    COORD myCoord = {10, 20 };
    SetConsolePosition(hConsole, myCoord);
    cout << "Hello!" << endl;
    Z.

  6. #6
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    There is no suck function as "SetConsolePosition" as far as I know
    Baaaaaaaaah

  7. #7
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Hi, I just found a little solution to that problem.
    You get the handle using "GetStdHandle" function
    Here is the code I used to set cursor's position:

    Code:
    #include <iostream.h>
    #include <windows.h>
    
    
    int main()
    {
    	int x;
    	HANDLE choutput;
    	COORD crd; 
    		crd.X = 8;
    		crd.Y = 9;
    		choutput = GetStdHandle(STD_OUTPUT_HANDLE);
    	SetConsoleTextAttribute(choutput, FOREGROUND_RED | FOREGROUND_GREEN 
    						| FOREGROUND_BLUE | FOREGROUND_INTENSITY 
    						| BACKGROUND_BLUE);
    		cout<<"\t\t\t Welcome to the DOS colour show\t\t\t\t";
    SetConsoleCursorPosition(choutput, crd);
    cin>>x;
    	return 0;
    }

    If you dont first set the consoleTextAttribute, it does not move the cursor. I dont know why it does that but I am just playing around with that and may be I will get a better solution for that
    Baaaaaaaaah

  8. #8
    Zaei
    Guest
    abdul. You probably should have read my post a bit better, before criticizing the code. The solution you just "found" was the first line.

    Z.

  9. #9
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    But it was not totally right.. was it?

    As I said above that there is no such function as "SetConsolePosition"
    Baaaaaaaaah

  10. #10
    Zaei
    Guest
    Sure, but i found the choice of "suck", instead of "such" quite interesting.

    Z.

  11. #11
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    Sometime, Unrelated words make a related word
    Baaaaaaaaah

  12. #12
    Sc0rp
    Guest
    Thanks for the solutions.
    I'll check them out.

  13. #13
    PowerPoster abdul's Avatar
    Join Date
    Dec 2000
    Location
    Ontario,Canada
    Posts
    2,827
    No Problem
    Baaaaaaaaah

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width