How to remove scrollbars in console windows C++

后端 未结 2 1670
我寻月下人不归
我寻月下人不归 2020-12-30 12:10

I have been checking out some Rogue like games (Larn, Rogue, etc) that are written in C and C++, and I have noticed that they do not have the scrollbars to the right of the

相关标签:
2条回答
  • 2020-12-30 12:40

    You need to make the console screen buffer the same size as the console window. Get the window size with GetConsoleScreenBufferInfo, srWindow member. Set the buffer size with SetConsoleScreenBufferSize().

    0 讨论(0)
  • 2020-12-30 12:55

    These guys show how to do it:

    #include <windows.h>
    #include <iostream>
    using namespace std;
    
    int main()
    {
        HANDLE hOut;
        CONSOLE_SCREEN_BUFFER_INFO SBInfo;
        COORD NewSBSize;
        int Status;
    
        hOut = GetStdHandle(STD_OUTPUT_HANDLE);
    
        GetConsoleScreenBufferInfo(hOut, &SBInfo);
        NewSBSize.X = SBInfo.dwSize.X - 2;
        NewSBSize.Y = SBInfo.dwSize.Y;
    
        Status = SetConsoleScreenBufferSize(hOut, NewSBSize);
        if (Status == 0)
        {
            Status = GetLastError();
            cout << "SetConsoleScreenBufferSize() failed! Reason : " << Status << endl;
            exit(Status);
        }
    
        GetConsoleScreenBufferInfo(hOut, &SBInfo);
    
        cout << "Screen Buffer Size : ";
        cout << SBInfo.dwSize.X << " x ";
        cout << SBInfo.dwSize.Y << endl;
    
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题