|
-
Oct 12th, 2002, 01:39 PM
#1
Thread Starter
Stuck in the 80s
[Resolved] Console Position
I know how I can set the caret to a specific x, y in the console window, but is there a way to retrieve the current coordinates of it?
I'm trying to make a function to go to the nth column in the console, but I want it to stay in the same row. I'm going to use this function in replace of setw() functions.
Thanks in advance for any help.
Last edited by The Hobo; Oct 14th, 2002 at 03:14 PM.
-
Oct 12th, 2002, 01:53 PM
#2
Fanatic Member
hmm.
perhaps you can havea a 2d array, and then set it wherever you want, and have a function that will update the screen with the array?
Visit www.fragblast.com
Gaming, forums, and a online RPG/Battle system
(__Flagg) DOT NET? is this a Hindi Dating service?
-
Oct 12th, 2002, 01:57 PM
#3
Thread Starter
Stuck in the 80s
Originally posted by nabeels786
hmm.
perhaps you can havea a 2d array, and then set it wherever you want, and have a function that will update the screen with the array?
I'm not sure what you mean...?
But I just found this: GetConsoleCursorInfo()
I'm going to see if I can figure out what it does real quick.
-
Oct 12th, 2002, 03:31 PM
#4
Thread Starter
Stuck in the 80s
Man...I figured there had to be a way to do this
-
Oct 12th, 2002, 04:08 PM
#5
Frenzied Member
it looks pretty complicated, I don't have time to whip up anything (sisters birthday dinner hehe)...but heres what I found: 
http://msdn.microsoft.com/library/de...bufferinfo.asp
BOOL GetConsoleScreenBufferInfo(
HANDLE hConsoleOutput,
PCONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo
);
Parameters
hConsoleOutput
[in] Handle to a console screen buffer. The handle must have the GENERIC_READ access right. For more information, see Console Buffer Security and Access Rights.
lpConsoleScreenBufferInfo
[out] Pointer to a CONSOLE_SCREEN_BUFFER_INFO structure that receives the console screen buffer information.
and about that consolescreenbuffer thing:
http://msdn.microsoft.com/library/de...r_info_str.asp
typedef struct _CONSOLE_SCREEN_BUFFER_INFO { COORD dwSize; COORD dwCursorPosition; WORD wAttributes; SMALL_RECT srWindow; COORD dwMaximumWindowSize;
} CONSOLE_SCREEN_BUFFER_INFO;
Members
dwSize
A COORD structure that contains the size of the console screen buffer, in character columns and rows.
dwCursorPosition
A COORD structure that contains the column and row coordinates of the cursor in the console screen buffer.
so it looks like with those 2 functions you can find the coordinates (seems like an awefull lot of work for it though)
-
Oct 12th, 2002, 04:11 PM
#6
Thread Starter
Stuck in the 80s
Thanks! I'll see what I can do with that
-
Oct 12th, 2002, 04:13 PM
#7
Frenzied Member
I don't think I'll have much time tonight...but if I do I'll give it a shot also
-
Oct 12th, 2002, 04:17 PM
#8
Thread Starter
Stuck in the 80s
I tried this:
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
CONSOLE_SCREEN_BUFFER_INFO info;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, info);
cout << info.dwSize.Y << endl;
return 0;
}
Gave the error:
C:\Download\The Guitar Hobo\Programming\Cpp Stuff\skipto\skipto.cpp(11) : error C2664: 'GetConsoleScreenBufferInfo' : cannot convert parameter 2 from 'struct _CONSOLE_SCREEN_BUFFER_INFO' to 'struct _CONSOLE_SCREEN_BUFFER_INFO *'
So I tried this:
Code:
#include <iostream>
#include <windows.h>
using namespace std;
int main() {
CONSOLE_SCREEN_BUFFER_INFO *info;
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleScreenBufferInfo(hConsole, info);
cout << info.dwSize.Y << endl;
return 0;
}
and got:
C:\Download\The Guitar Hobo\Programming\Cpp Stuff\skipto\skipto.cpp(13) : error C2228: left of '.dwSize' must have class/struct/union type
What am I doing wrong here?
-
Oct 12th, 2002, 04:17 PM
#9
Thread Starter
Stuck in the 80s
Originally posted by SteveCRM
I don't think I'll have much time tonight...but if I do I'll give it a shot also
That's cool, man. Any help you can give and have given is much appreciated.
-
Oct 12th, 2002, 04:20 PM
#10
Thread Starter
Stuck in the 80s
When I do do something to get it working, it just gives me 25?
-
Oct 12th, 2002, 04:28 PM
#11
Frenzied Member
huh...i get the same...hmmmm...25 is the height of the console isn't it? maybe...eh I'll think about it
it returns 80 for the x, thats also an extreme of the console...hmmm
-
Oct 12th, 2002, 04:33 PM
#12
Thread Starter
Stuck in the 80s
doh!
We were using dwSize. dwCursorPosition has the right values.
It works perfectly (I think)
Thanks a lot, man!
-
Oct 12th, 2002, 04:38 PM
#13
Thread Starter
Stuck in the 80s
This is what I did with it, btw:
Code:
#include <iostream>
#include <windows.h>
using namespace std;
void setXPos(int x);
int main() {
setXPos(10);
cout << "Test!" << endl << endl;
return 0;
}
void setXPos(int x) {
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
COORD coord;
GetConsoleScreenBufferInfo(hConsole, &csbiInfo);
coord.X = x;
coord.Y = csbiInfo.dwCursorPosition.Y;
SetConsoleCursorPosition(hConsole, coord);
}
Thanks again, Steve!
-
Oct 12th, 2002, 06:45 PM
#14
Frenzied Member
lol woops anytime
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
|