鱼C论坛

 找回密码
 立即注册
查看: 1651|回复: 0

[技术交流] 自己写的一个可以设置控制台光标的类

[复制链接]
发表于 2019-9-16 21:45:35 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
本帖最后由 bin554385863 于 2019-9-16 21:47 编辑

GameWnd.h
#include <windows.h>
#include <cstdio>
class GameWnd
{
private:
    TCHAR *Title;   //窗口标题
    int Fclr, Bclr; //前景色,背景色
    COORD Pos;
    HANDLE winHandle; //窗口句柄
public:
    GameWnd(TCHAR *t = nullptr) : Title(t)
    {
        winHandle = GetStdHandle(STD_OUTPUT_HANDLE);
        SetConsoleTitle(Title);
    }
    void SetColor(int fclr, int bclr);
    void SetPosition(short x, short y);
    void CleanScr(short begx, short begy, int endx, int endy);
    ~GameWnd() {}
};
void GameWnd::SetColor(int fclr, int bclr)
{
    Fclr = fclr;
    Bclr = bclr;
    SetConsoleTextAttribute(winHandle, Fclr + Bclr * 0x10);
}
void GameWnd::SetPosition(short x, short y)
{
    Pos = {x, y};
    SetConsoleCursorPosition(winHandle, Pos);
}
void GameWnd::CleanScr(short begx, short begy, int endx, int endy)
{
    for (size_t i = begx; i < endx; i++)
    {
        for (size_t j = begy; j < endy; j++)
        {
            SetPosition(i, j);
            printf(" ");
        }
        printf("\n");
    }
}
---------------------------------------------------------------------------------
Game.cpp
#include "GameWnd.h"
#include <iostream>
int main()
{
        char t[] = "*******";
        GameWnd wnd = t;
        wnd.SetColor(2, 0);
   wnd.SetPosition(0,0);
        for (int i = 0; i < 6; i++)
        {
                for (int j = 0; j < 160; j++)
                {
                        printf("*");
                }
                printf("\n");
        }
        wnd.CleanScr(3,1,157,5);
        wnd.SetPosition(80, 2);
        std::cout<<"八格牙路";
        wnd.SetPosition(170, 8);
        return 0;
}
-----------------------------------------------------------------------------------------------------------
****************************************************************************************************************************************************************
***                                                                                                                                                                                                                                                                             ***
***                                                                                                                          八格牙路                                                                                                                                       ***
***                                                                                                                                                                                                                                                                             .***                                                                                                                                                          ****************************************************************************************************************************************************************

E:\Users\86184\Documents\Code>
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-4 09:24

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表