Click to See Complete Forum and Search --> : Locating the cursor at a specific coordinate
Sc0rp
Jul 30th, 2001, 04:57 AM
How do I write text in a specific place on the screen in a console app?
Sc0rp
Jul 30th, 2001, 05:13 AM
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()?
abdul
Jul 30th, 2001, 11:56 AM
Try this:
#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!
Sc0rp
Jul 30th, 2001, 12:35 PM
Thanks, but my VC++6 doesn't recognize this function either. :(
Any other ideas?
Zaei
Jul 30th, 2001, 03:22 PM
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD myCoord = {10, 20 };
SetConsolePosition(hConsole, myCoord);
cout << "Hello!" << endl;
Z.
abdul
Jul 30th, 2001, 04:28 PM
There is no suck function as "SetConsolePosition" as far as I know :p
abdul
Jul 30th, 2001, 05:20 PM
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:
#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:)
Zaei
Jul 30th, 2001, 05:45 PM
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.
abdul
Jul 30th, 2001, 05:58 PM
But it was not totally right.. was it?
As I said above that there is no such function as "SetConsolePosition"
Zaei
Jul 30th, 2001, 07:20 PM
Sure, but i found the choice of "suck", instead of "such" quite interesting.
Z.
abdul
Jul 30th, 2001, 08:40 PM
Sometime, Unrelated words make a related word:D
Sc0rp
Jul 31st, 2001, 04:49 AM
Thanks for the solutions. :)
I'll check them out.
abdul
Jul 31st, 2001, 11:15 AM
No Problem:D
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.