这个问题是我之前题为How to fix this procedure writing a string to the console screen buffer 的帖子的后续问题。
我想在写入任意字符串之前将光标设置到给定的 (x,y) 位置:
GotoXY(x,y)
SendLn('The harder they come...');
怎样才能procedure GotoXY(x, y: integer)
实施?
这个问题是我之前题为How to fix this procedure writing a string to the console screen buffer 的帖子的后续问题。
我想在写入任意字符串之前将光标设置到给定的 (x,y) 位置:
GotoXY(x,y)
SendLn('The harder they come...');
怎样才能procedure GotoXY(x, y: integer)
实施?
一个快速的谷歌揭示
作为参考,这是我对这个问题的解决方案,基于 JamesB 的帖子(接受的答案):
procedure GotoXY(x, y: Integer);
var
CursorCoord: _COORD;
begin
CursorCoord.x := x;
CursorCoord.y := y;
SetConsoleCursorPosition(hStdOut, CursorCoord);
end;
编辑:
上面 jamesB 引用的页面还指向另一个有趣的相关资源,即GetConsoleScreenBufferInfo 函数。
在控制台屏幕缓冲区中获取光标的列和行坐标也是我的要求的一部分。
以下是我根据引用的资源编写的 2 个 Delphi 函数:
var
Buffer: _Console_Screen_Buffer_Info;
...
function WhereX: Integer;
begin
GetConsoleScreenBufferInfo(hStdOut,Buffer);
//
Result:=Buffer.dwCursorPosition.X;
end;
function WhereY: Integer;
begin
GetConsoleScreenBufferInfo(hStdOut,Buffer);
//
Result:=Buffer.dwCursorPosition.Y;
end;