简体   繁体   English

Borland C ++控制台功能

[英]Borland c++ console functions

I'm studing now and I got this homework / tasks to do: 我现在正在学习,我要做以下家庭作业/任务:

1) If you press the CTRL + L key, all numeric symbols should change the color. 1)如果按CTRL + L键,则所有数字符号都应更改颜色。

2) If you press the CTRL + S key, you will get the length of the word, left from the cursor. 2)如果按CTRL + S键,您将获得单词的长度,该长度从光标左侧开始。

I found this function int bioskey(int cmd); 我发现此功能int bioskey(int cmd); So now I can check if the key is pressed, but how to change the color only of numeric symbols, or read words from console to get their length ? 因此,现在我可以检查是否按下了键,但是如何仅更改数字符号的颜色,或者如何从控制台读取单词以获取其长度?

Some of us still remember the MS-DOS (let it rest in peace or pieces...) 我们中有些人还记得MS-DOS (让它安息吧……)

if you are really in MS-DOS then you can not expect that the content of the console would be changed in colors for only specific areas. 如果您确实在使用MS-DOS,则不能指望控制台的内容将仅针对特定区域以颜色更改。 You need to do that your self. 您需要自己做。 The problem is we do not know anything about your project background so we do not know what and how yours stuff is represented,rendered/outputed/inputed etc... 问题是我们对您的项目背景一无所知,所以我们不知道您的东西是什么以及如何表示,渲染/输出/输入等。

I assume EGA/VGA BIOS text mode is used so you can exploit direct access to the VRAM . 我假设使用了EGA / VGA BIOS文本模式,因此您可以利用对VRAM的直接访问。 So you need to set pointer to the address B800:0000 and handle it as array where each character on screen has 2 BYTEs. 因此,您需要将指针设置为地址B800:0000并将其作为数组处理,其中屏幕上的每个字符都有2个BYTE。 one is color attribute and the other is ASCII code (not sure in which order anymore)... 一个是颜色属性,另一个是ASCII代码(不再确定顺序)...

So for already rendered stuff you just: 因此,对于已经渲染的东西,您只需:

  1. loop through whole screen 遍历整个屏幕

    usually 80x25x2 Bytes 通常是80x25x2字节

  2. test each ASCII for alpha numeric value 测试每个ASCII字母数字值

    so ASCII code >= '0' and code<='9' for numbers or add all the stuff you are considering as alphanumeric like code>' ' and code<='9' . 因此,ASCII code >= '0'code<='9'表示数字,或者添加您考虑作为字母数字的所有内容,例如code>' 'code<='9'

  3. change colors for selected characters 更改所选字符的颜色

    just by changing the attribute byte. 只需更改属性字节即可。

When you put it together for numbers it will look like this: 当您将它们放在一起计算数字时,它将看起来像这样:

char far *scr=(char far*)0x0B0000000;
int x,y,a;
for (a=0,y=0;y<25;y++)
 for (x=0;x<80;x++,a+=2)
  if ((scr[a+0]>='0')&&((scr[a+0]<='9'))
  {
  scr[a+1]=7; //attribute with the different color here
  }

if it does not work than try swap scr[a+0] and scr[a+1] . 如果不起作用,请尝试交换scr[a+0]scr[a+1] If an exception occur then you are not in MS-DOS and you do not have access to VRAM . 如果发生异常,则您不在MS-DOS中,并且您无权访问VRAM In that case use DOS-BOX or driver that allows access to memory like dllportio ... For more info see some more or less related QA's: 在这种情况下,请使用DOS-BOX或允许访问诸如dllportio之类的内存的驱动程序。有关更多信息,请参见一些相关的QA:

If you got problem with the CTRL+Key detection not sure if in-build function in TC++ allows CTRL (was too long ago) then you can exploit BIOS or even hook up the keyboard ISR . 如果您在CTRL+Key检测方面遇到问题,请不确定TC ++中的内置功能是否允许CTRL (在很久以前),那么您可以利用BIOS甚至挂接键盘ISR See the second link where ISR for keyboard handler is there present... You can port it to C++ or google there must be a lot of examples out there especially TP7.0 (which is pascal but easily portable to TC++ ) 请参阅第二个链接,其中存在用于键盘处理程序的ISR ...您可以将其移植到C ++或google,那里必须有很多示例,尤其是TP7.0 (这是pascal的,但很容易移植到TC ++

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM