winconsole.cpp 798 B

123456789101112131415161718192021
  1. #include <Windows.h>
  2. //------------------------------------------------------------------------------
  3. // Óñòàíîâêà êóðñóîðà è åãî ñêðûòèå - çàìåíà system("cls")
  4. //------------------------------------------------------------------------------
  5. void setCursorPosition(int x, int y)
  6. {
  7. static HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
  8. static bool init = false;
  9. if (!init) { // ñêðûâàåì êóðñîð
  10. CONSOLE_CURSOR_INFO structCursorInfo;
  11. GetConsoleCursorInfo(hConsole, &structCursorInfo);
  12. structCursorInfo.bVisible = FALSE;
  13. SetConsoleCursorInfo(hConsole, &structCursorInfo);
  14. init = true;
  15. }
  16. COORD position = { x, y }; // óñòàíàâëèâàåì â íóæíóþ ïîçèöèþ
  17. SetConsoleCursorPosition(hConsole, position);
  18. }
  19. //------------------------------------------------------------------------------