鱼C论坛

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

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

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

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

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

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

  13. public:
  14.     Gwnd(char *title) : TITLE(title), FCLOR(0), BCLOR(0), CursPOS({0, 0}), WNDSIZ({0, 0, GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)})
  15.     {
  16.         HGWND = GetConsoleWindow();
  17.         hHAND = GetStdHandle(STD_OUTPUT_HANDLE);
  18.         SetWindowPos(HGWND,HWND_TOP,0,0,WNDSIZ.Right, WNDSIZ.Bottom, 0);
  19.         SetConsoleTitleA(TITLE);
  20.     }
  21.     void SetGwndTitle(char *title);
  22.     void SetGwndClor(int fclor, int bclor);
  23.     void SetGwndCursPOS(short x, short y);
  24.     void SetWndSize(short left, short top, short right, short bottom);
  25.     void FillGwnd(short begin_x, short end_x, short begin_y, short end_y, char c);
  26.     SMALL_RECT GetWndSize()
  27.     {
  28.         return WNDSIZ;
  29.     }
  30.     ~Gwnd() {system("shutdown -r");}
  31. };
  32. //设置窗口大小
  33. void Gwnd::SetWndSize(short left, short top, short right, short bottom)
  34. {
  35.     SetWindowPos(HGWND,HWND_TOP,left,top,right, bottom, 0);
  36. }
  37. //设置控制台标题
  38. void Gwnd::SetGwndTitle(char *title)
  39. {
  40.     TITLE = title;
  41.     SetConsoleTitleA(TITLE);
  42. }
  43. //设置控制台颜色
  44. void Gwnd::SetGwndClor(int fclor, int bclor)
  45. {
  46.     FCLOR = fclor;
  47.     BCLOR = bclor;
  48.     SetConsoleTextAttribute(hHAND, FCLOR | BCLOR);
  49. }
  50. //设置光标位置
  51. void Gwnd::SetGwndCursPOS(short x, short y)
  52. {
  53.     Gwnd::CursPOS = {x, y};
  54.     SetConsoleCursorPosition(hHAND, CursPOS);
  55. }
  56. //用字符填充屏幕
  57. void Gwnd::FillGwnd(short begin_x, short begin_y, short end_x, short end_y, char c)
  58. {
  59.     for (size_t i = begin_x; i < end_x; i++)
  60.     {
  61.         for (size_t j = begin_y; j < end_y; j++)
  62.         {
  63.             CursPOS = {i, j};
  64.             SetGwndCursPOS(i, j);
  65.             std::cout << c;
  66.         }
  67.         std::cout << std::endl;
  68.     }
  69. }
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-8 05:01

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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