#include "CConsole.h" CConsole::CConsole() { m_hConsole = GetStdHandle(STD_OUTPUT_HANDLE); GetConsoleScreenBufferInfo(m_hConsole, &m_hBufferInfo); m_coordLargestWindowSize = GetLargestConsoleWindowSize(m_hConsole); } CConsole::CConsole(DWORD _dwConsole) { m_hConsole = GetStdHandle(_dwConsole); GetConsoleScreenBufferInfo(m_hConsole,&m_hBufferInfo); m_coordLargestWindowSize = GetLargestConsoleWindowSize(m_hConsole); } void CConsole::SetWindowSize(int _width, int _height) { HRESULT hResult; /// Clamp values to fit the current status of the console and prevent errors. COORD hDimensions; if (_height > MAX_CONSOLE_BUFFER_HEIGHT) _height = MAX_CONSOLE_BUFFER_HEIGHT; hDimensions.X = _width < m_hBufferInfo.dwSize.X ? m_hBufferInfo.dwSize.X : _width; hDimensions.Y = _height < m_hBufferInfo.dwSize.Y ? m_hBufferInfo.dwSize.Y : _height; hDimensions.Y += 5; //Offset to prevent deLeting old results if (!SetConsoleScreenBufferSize(m_hConsole, hDimensions)) hResult = HRESULT_FROM_WIN32(GetLastError()); /// Set new window size to achieve the optimal layout SMALL_RECT hRect; hRect.Left = 0; hRect.Top = 0; hRect.Bottom = m_hBufferInfo.srWindow.Bottom; hRect.Right = hDimensions.X - 1; if (!SetConsoleWindowInfo(m_hConsole, TRUE, &hRect)) hResult = HRESULT_FROM_WIN32(GetLastError()); /// Update the buffer info GetConsoleScreenBufferInfo(m_hConsole, &m_hBufferInfo); } void CConsole::SetCursorPosition(short _xPos, short _yCord) { SetConsoleCursorPosition(m_hConsole, { _xPos, _yCord }); } void CConsole::ClearScreen() { system("cls"); }