首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在c++中,在不使用窗口句柄的情况下更改光标位置。Qbasic模仿慢

在c++中,在不使用窗口句柄的情况下更改光标位置。Qbasic模仿慢
EN

Stack Overflow用户
提问于 2012-08-03 10:56:20
回答 1查看 613关注 0票数 0

有时,我需要在屏幕上写东西(例如:第10列和第20行)。我在网络上搜索,发现它是通过使用windows处理程序完成的,后者使用的是windows.h。

是的,使用句柄速度快,但有点复杂,所以我编写了一个类,它只使用printf( string ),并以适合屏幕的方式更改字符串,每个printf命令都填充整个80x24控制台屏幕。这个类模仿QBasic的CLS,定位x,y和打印命令。

问题:是否有一种更简单的方法来到达屏幕上的任何位置,在不使用窗口句柄或像我这样的慢类的情况下放置一个字符或一个点(绘图)?

我的QBASIC类太慢了,所以每秒只能使用几次。VC++ 10.0 windows XP

耽误您时间,实在对不起。

这是我的课和一些例子:

代码语言:javascript
复制
// print_test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
class QBASIC
{
public:
QBASIC()
{
    for(int i=0;i<(80*23);i++)
    {
        default_fill[i]=' ';
        current_fill[i]=' ';
    }
    default_fill[80*23]=NULL;
    current_fill[80*23]=NULL;
    row=0;
    column=0;
    window_number=0;

}
void locate(int x,int y)
{
    row=y;
    column=x;
    return;
}
void print(char* text)
{
    int length=strlen(text);
    for(int i=0;i<length;i++)
    {
        current_fill[row*80+column+i]=text[i];
    }
    row++;
    column=0;
    printf("%s",current_fill);

    return;
}
void cls()
{
    for(int i=0;i<(80*24);i++)
    {
        current_fill[i]=default_fill[i];
    }
    column=0;
    row=0;
    printf("%s",current_fill);

}
void window(int x1,int y1,int x2,int y2,char*text,int id)
{
    //178 wall code
    window_buffer[window_number]=new unsigned char[1000];
    window_number++;
    for(int i=x1;i<(x2+1);i++)
    {
        current_fill[i+80*y1]=178;
        current_fill[i+80*y2]=178;

    }
    for(int j=y1;j<(y2+1);j++)
    {
        current_fill[x1+80*j]=178;
        current_fill[x2+80*j]=178;

    }
    int length=strlen(text);int temp_row=0;int temp_column=0;
    for(int i=0;i<length;i++)
    {
        if(current_fill[(x1+1+temp_column)+(y1+1+temp_row)*80+i]!=178)
        {
        current_fill[(x1+1+temp_column)+(y1+1+temp_row)*80+i]=text[i];
        }
        else
        {
            temp_row++;
            temp_column=-i;
            current_fill[(x1+1+temp_column)+(y1+1+temp_row)*80+i]=text[i];

        }

    }
    printf("%s",current_fill);
    return;
}
private:
unsigned char default_fill[80*23+1000];
unsigned char current_fill[80*23+1000];
int row,column;
unsigned char *window_buffer[10];//max windows number=10
int window_number;

};

int main()
{
QBASIC *mimic=new QBASIC();
mimic->cls();
mimic->locate(25,10);
mimic->print("x <--here is 26th column and 11th row");

mimic->locate(5,4);
mimic->print("x <--here is 6th column and 5th row");

mimic->locate(0,0);
mimic->print("x <--here is origin");


mimic->print("x <--here is sequantial print after");
mimic->print("x <--here is another");
int window_id_1=0,window_id_2=1;
mimic->window(20,5,28,9,"this is a window",window_id_1);
mimic->window(10,18,70,22,"this is another window from 10,18 to 70,22",window_id_2);


delete mimic;


getchar();// waiting to see the screen before exiting. press enter to continue
return 0;
}

我认为没有解决办法。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-08-03 11:18:21

好的,我会继续使用句柄。

代码语言:javascript
复制
void LOCATE(int x, int y)
{
  COORD newPosition = { x, y };
  HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE);
  SetConsoleCursorPosition(h, newPosition);
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11794355

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档