Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==========ШАБЛОН ПЕЧАТИ МЕНЮ==========
- void print_menu(int sym, const string items[]) {
- const int N_ITEMS = 5;
- //========================
- //========================
- //========================
- HANDLE hCon;
- COORD cPos;
- int width = 0, height = 0;
- // вытакиваем ширину и высоту
- hCon = GetStdHandle(-12);
- CONSOLE_SCREEN_BUFFER_INFO consoleInfo;
- if (GetConsoleScreenBufferInfo(hCon, &consoleInfo))
- {
- width = consoleInfo.srWindow.Right - consoleInfo.srWindow.Left + 1;
- height = consoleInfo.srWindow.Bottom - consoleInfo.srWindow.Top + 1;
- }
- // меняем положение меню
- hCon = GetStdHandle(STD_OUTPUT_HANDLE);
- cPos.Y = 15;
- cPos.X = 0;
- SetConsoleCursorPosition(hCon, cPos);
- // меняем размер шрифта
- CONSOLE_FONT_INFOEX cfi;
- cfi.cbSize = sizeof(cfi);
- cfi.nFont = 0;
- cfi.dwFontSize.X = 0; // Width of each character in the font
- cfi.dwFontSize.Y = 24; // Height
- cfi.FontFamily = FF_DONTCARE;
- cfi.FontWeight = FW_NORMAL;
- SetCurrentConsoleFontEx(GetStdHandle(STD_OUTPUT_HANDLE), FALSE, &cfi);
- //========================
- //========================
- //========================
- for (int i = 1; i <= N_ITEMS; i++) {
- SetColor(7, 0);
- cout << " ";
- if (i == sym) {
- SetColor(7, 5);
- }
- cout << items[i - 1] << endl;
- SetColor(7, 0);
- }
- }
- // ==========МЕНЮ==========
- int menu(int& active, const string items[]) {
- wint_t buf;
- do {
- cls();
- print_menu(active, items);
- buf = _getwch();
- switch (buf) {
- case up: // клавиша вверх
- if (active > 1) active--;
- break;
- case down: // клавиша вниз
- if (active < 5) active++;
- break;
- case enter: // клавиша enter
- return active;
- case esc: // клавиша escape
- return 5;
- }
- } while (1);
- }
- // ==========УСТАНОВКА ЦВЕТА ТЕКСТА И ФОНА==========
- void SetColor(int text, int bg) {
- HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
- SetConsoleTextAttribute(hStdOut, (WORD)((bg << 4) | text));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement