Get cursor position in Win Console App

I've come this far, but what I want to achieve is:
*I want to get Pixel Position(XY) of Cursor(NOT MOUSE) position in console and then draw a line to that position ...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
HWND console_handle = GetConsoleWindow();
	HDC device_context = GetDC(console_handle);
	//int x = 0; int y = 0;
	//Here's a 5 pixels wide RED line [from initial 0,0] to 300,300
	

	HPEN pen = CreatePen(PS_SOLID, 5, RGB(255, 0, 0));
        POINT p1;
	POINT p2;

	GetCursorPos(&p1); // But this get MOUSE CURSOR POS I DONT WANT THAT.
        GetCursorPos(&p1); // But this get MOUSE CURSOR POS I DONT WANT THAT.

        SelectObject(device_context, pen);
	LineTo(device_context, p2.x, p2.y);


	ReleaseDC(console_handle, device_context);

Last edited on
You can use GetConsoleScreenBufferInfo
I already use that :
1
2
3
4
5
6
7
8
9
               void getCursorXY(int &x, int&y) {
	
		CONSOLE_SCREEN_BUFFER_INFO csbi;
	
		if (GetConsoleScreenBufferInfo(GetStdHandle(STD_OUTPUT_HANDLE), &csbi)) {	
			x = csbi.dwCursorPosition.X;
			y = csbi.dwCursorPosition.Y;		
		}
}

But It doesn't get Pixel position...
Topic archived. No new replies allowed.