【发布时间】:2012-03-30 15:43:03
【问题描述】:
这个问题是我之前题为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)如何实现?
【问题讨论】:
-
问题是您为什么使用
WriteFile写入控制台。使用控制台 API,例如WriteConsole和朋友们。 -
@David Heffernan:谢谢:len:=Length(s); WriteConsole(hStdOut, @s[1],len,len,nil);完成这项工作。
-
请记住,如果标准输出被重定向到一个文件,那么 WriteConsole 将会失败。
-
幸运的是,这不是我的要求。
-
或者更简单,获取JEDI JCLs
JCLConsole,并使用JCLScreenBuffer.Write(Text, X, Y, Attributes)方法。 :)Attributes默认为 nil,因此您可以排除它以使用默认文本和背景颜色。
标签: delphi winapi delphi-xe windows-console