我一直在检查一些用C和C++编写的Rogue like games(Larn,Rogue等),并且我注意到它们在控制台窗口的右侧没有滚动条。

我该如何完成相同的功能?

最佳答案

These guys展示如何做:

#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;
}

关于c++ - 如何在控制台Windows C++中删除滚动条,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/3471520/

10-10 07:26