在c中使用graphics.h中的outtextxy实现退格键
我试图用 c 语言创建一个文本编辑器。但我面临退格字符的问题。当我尝试用 outtextxy 打印此内容时,出现了一个奇怪的字符。 我尝试了以下退格键代码:
str[2]="\b ";
outtextxy(x,y,str);
这在文本模式下工作正常,但不起作用在图形模式下。
I was trying to create a text editor in c. but i am facing a problem with the backspace character. and when i am trying to print this with outtextxy a strange character is appearing.
i tried following code for this backspace:
str[2]="\b ";
outtextxy(x,y,str);
This is working fine under textmode but not working under graphics mode.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
距离我上次看到它已经过去了整整 20 年。它是BGI(IIRC)中的低级图形输出函数。您将获得代码 8 的字形,即 OEM 字符集中的一个带圆圈的矩形。
要使其像 put() 那样工作,您必须自己解释控制代码。如果您看到退格键(字符 8),则必须更新内部“光标位置”变量并将 x 向后移动字体宽度。与“\n”(增加 y)和“\r”(将 x 设置为 0)相同。
That's been a good 20 years since I last laid eyes on that. It is a low-level graphics output function in BGI (IIRC). You'll get the glyph for code 8, a rectangle with a circle in the OEM character set.
To make it act like, say, puts(), you'll have to interpret the control codes yourself. If you see a backspace (char 8), you'll have to update your internal "cursor position" variable and move x back by the font width. Same for '\n' (increment y) and '\r' (set x to 0).
由于您处于图形模式:
[第 1 步]使用两个整数(例如 x,y)跟踪当前位置
[步骤 2] 每当按下退格键时:
第一次检查 x==0,y==0 :发出蜂鸣声;
否则检查 x==0, y>0 :然后使 x= screen-width, y=y-1;
否则检查是否 x>0, y>0 :则 x=x-1;
现在你有了正确的 x,y 坐标,只是 outtextxy 在该位置有一个 NULL/空格字符。
注意:在outtextxy之后不要增加x,因为光标仍应该位于前一个字符位置。
祝你好运!!
Since U are in Graphics mode:
[STEP 1] Keep track of current position using two ints (say x,y)
[STEP 2] Whenever backspace is pressed:
1st Check if x==0,y==0 : Emit a beep;
Else check if x==0, y>0 : Then make x= screen-width, y=y-1;
Else check if x>0, y>0 : Then x=x-1;
Now That U hav the right x,y co-ordinates, just outtextxy a NULL/space character at the position.
NOTE: After outtextxy do NOT increment x as the cursor is still supposed to be at the prev character position.
GOOD LUCK!!