この質問は、 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 functionも示しています。
コンソール画面バッファー内のカーソルの列と行の座標を取得することも、私の要件の一部です。
以下は、引用されたリソースに基づいて作成した 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;