|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
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;
- }
- }
复制代码 |
|