|
-
Jul 30th, 2001, 04:57 AM
#1
Locating the cursor at a specific coordinate
How do I write text in a specific place on the screen in a console app?
-
Jul 30th, 2001, 05:13 AM
#2
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()?
-
Jul 30th, 2001, 11:56 AM
#3
PowerPoster
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!
-
Jul 30th, 2001, 12:35 PM
#4
Thanks, but my VC++6 doesn't recognize this function either. 
Any other ideas?
-
Jul 30th, 2001, 03:22 PM
#5
Code:
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
COORD myCoord = {10, 20 };
SetConsolePosition(hConsole, myCoord);
cout << "Hello!" << endl;
Z.
-
Jul 30th, 2001, 04:28 PM
#6
PowerPoster
There is no suck function as "SetConsolePosition" as far as I know
-
Jul 30th, 2001, 05:20 PM
#7
PowerPoster
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
-
Jul 30th, 2001, 05:45 PM
#8
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.
-
Jul 30th, 2001, 05:58 PM
#9
PowerPoster
But it was not totally right.. was it?
As I said above that there is no such function as "SetConsolePosition"
-
Jul 30th, 2001, 07:20 PM
#10
Sure, but i found the choice of "suck", instead of "such" quite interesting.
Z.
-
Jul 30th, 2001, 08:40 PM
#11
PowerPoster
Sometime, Unrelated words make a related word
-
Jul 31st, 2001, 04:49 AM
#12
Thanks for the solutions. 
I'll check them out.
-
Jul 31st, 2001, 11:15 AM
#13
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|