hi everyone, my name is Atique and i am new to the forum so my regards to all, i'm working in vc++ 6.0 and i need a function that gives the current coordinates of the console window.
thanks for your precious time.
hi everyone, my name is Atique and i am new to the forum so my regards to all, i'm working in vc++ 6.0 and i need a function that gives the current coordinates of the console window.
thanks for your precious time.
In C there is ncurses library.In C++ i do not anything that answer your question.So i suggest you to write a class in order to wrap this C library.Then you can handle it as an object and that's it However i have never tried it
that's a bit of an ambiguous question.
do you want the coordinates of the cursor in the window?
do you want the coordinates of the window itself?
did you not notice the windows programming forum, which would have been a more appropriate place for this question?
I think you want the GetCursorPos function :
Code:#include <stdio.h> #include <windows.h> int main(void) { LPPOINT Coord; while(1) { GetCursorPos(Coord); printf("X: %d Y: %d\n", Coord->x, Coord->y); Sleep(1000); } //return 0; }
I hope that I have helped .
Boom -> seg fault
better would be
KurtCode:#include <stdio.h> #include <windows.h> int main(void) { POINT Coord; while(1) { GetCursorPos(& Coord); printf("X: %d Y: %d\n", Coord.x, Coord.y); Sleep(1000); } //return 0; }
thanks a lot everyone for such a good response,
Elkvis i want the windows coordinates itself, i was a little reluctant from that windows forum because i know nothing about windows programming,
Actually i am making a chess game which uses a lot of bitmaps, and is handled with mouse, since i am not aware of windows programming so the game involves a little hard coded stuff, because of that i have to move the console-window to the corner otherwise it creates problem, so i need a function that tells the current window position, i would subtract it from the mouse cords and the problem is solved.
Better would be,
std::cout << "X: " << Coord.x << " Y: " << Coord.y << "\n";
Since this is C++, after all.
Anyway, I recommend you ditch this approach and VC++ 6 (why do you use such an old version anyway?) and focus your efforts on finding a GUI library instead.
Noone wants to use a console for a game.
Is this is a bad time for a "PS3 has no games" joke?Noone wants to use a console for a game.
GetCursorPos is not even the right API. That's for moving the thing that your mouse controls.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"
O_o
I believe that the intent was to say that `GetConsoleScreenBufferInfo' and `SetConsoleCursorPosition' would be needed for the console cursor instead of `GetCursorPos' and `SetCursorPos' which is for the mouse cursor.
Soma
thanks a lot everyone for such a good response, i have just got the answer form that windows programming forum ' thanks to Elkvis '.
Code:#include <windows.h> #include <iostream> using namespace std; int main() { HWND conwin = GetConsoleWindow(); RECT conrect; if (!conwin || !GetWindowRect(conwin, &conrect)) { cerr << "Error" << endl; return 1; }//if cout << "(" << conrect.left << "," << conrect.top << ")-(" << conrect.right << "," << conrect.bottom << ")" << endl; int width = conrect.right - conrect.left; int height = conrect.bottom - conrect.top; cout << "W=" << width << endl; cout << "H=" << height << endl; cout << "Moving to 0,0...." << endl; MoveWindow(conwin, 0, 0, width, height, TRUE); return 0; }//main
Well it appears you asked the wrong question then because it appears that all you wanted was to know how to move the window to the top-left corner of your screen.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"