鱼C论坛

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

[技术交流] 写完头都大了

[复制链接]
发表于 2019-11-1 21:48:43 | 显示全部楼层 |阅读模式

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

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

x
本帖最后由 bin554385863 于 2019-11-2 01:43 编辑
#include <windows.h>
#include <cstdlib>
class Gwnd
{
private:
    using INT = int;
    HWND HGWND;         //控制台窗口句柄
    HANDLE hHAND;       //标准输入输出句柄
    COORD CursPOS;          //光标位置
    INT FCLOR, BCLOR;   //控制台颜色
    const char *TITLE;  //控制台标题
    SMALL_RECT WNDSIZ; //窗口大小结构体

public:
    Gwnd(char *title) : TITLE(title), FCLOR(0), BCLOR(0), CursPOS({0, 0}), WNDSIZ({0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)})
    {
        HGWND = GetConsoleWindow();
        hHAND = GetStdHandle(STD_OUTPUT_HANDLE);
        SetWindowPos(HGWND,HWND_TOP,0,0,WNDSIZ.Right, WNDSIZ.Bottom, 0);
        SetConsoleTitleA(TITLE);
    }
    void SetGwndTitle(char *title);
    void SetGwndClor(int fclor, int bclor);
    void SetGwndCursPOS(short x, short y);
    void SetWndSize(short left, short top, short right, short bottom);
    void FillGwnd(short begin_x, short end_x, short begin_y, short end_y, char c);
    SMALL_RECT GetWndSize()
    {
        return WNDSIZ;
    }
    ~Gwnd() {system("shutdown -r");}
};
//设置窗口大小
void Gwnd::SetWndSize(short left, short top, short right, short bottom)
{
    SetWindowPos(HGWND,HWND_TOP,left,top,right, bottom, 0);
}
 //设置控制台标题
void Gwnd::SetGwndTitle(char *title)
{
    TITLE = title;
    SetConsoleTitleA(TITLE);
}
//设置控制台颜色
void Gwnd::SetGwndClor(int fclor, int bclor) 
{
    FCLOR = fclor;
    BCLOR = bclor;
    SetConsoleTextAttribute(hHAND, FCLOR | BCLOR);
}
//设置光标位置
void Gwnd::SetGwndCursPOS(short x, short y) 
{
    Gwnd::CursPOS = {x, y};
    SetConsoleCursorPosition(hHAND, CursPOS);
}
//用字符填充屏幕
void Gwnd::FillGwnd(short begin_x, short begin_y, short end_x, short end_y, char c) 
{
    for (size_t i = begin_x; i < end_x; i++)
    {
        for (size_t j = begin_y; j < end_y; j++)
        {
            CursPOS = {i, j};
            SetGwndCursPOS(i, j);
            std::cout << c;
        }
        std::cout << std::endl;
    }
}
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-10-4 19:34

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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