gpt4 book ai didi

c++ - 如何删除控制台窗口 C++ 中的滚动条

转载 作者:可可西里 更新时间:2023-11-01 12:45:21 33 4
gpt4 key购买 nike

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

我怎样才能完成同样的功能?

最佳答案

要删除滚动条,只需将屏幕缓冲区高度设置为与窗口高度相同:

#include <windows.h>
#include <iostream>
using namespace std;

int main()
{
// get handle to the console window
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);

// retrieve screen buffer info
CONSOLE_SCREEN_BUFFER_INFO scrBufferInfo;
GetConsoleScreenBufferInfo(hOut, &scrBufferInfo);

// current window size
short winWidth = scrBufferInfo.srWindow.Right - scrBufferInfo.srWindow.Left + 1;
short winHeight = scrBufferInfo.srWindow.Bottom - scrBufferInfo.srWindow.Top + 1;

// current screen buffer size
short scrBufferWidth = scrBufferInfo.dwSize.X;
short scrBufferHeight = scrBufferInfo.dwSize.Y;

// to remove the scrollbar, make sure the window height matches the screen buffer height
COORD newSize;
newSize.X = scrBufferWidth;
newSize.Y = winHeight;

// set the new screen buffer dimensions
int Status = SetConsoleScreenBufferSize(hOut, newSize);
if (Status == 0)
{
cout << "SetConsoleScreenBufferSize() failed! Reason : " << GetLastError() << endl;
exit(Status);
}

// print the current screen buffer dimensions
GetConsoleScreenBufferInfo(hOut, &scrBufferInfo);
cout << "Screen Buffer Size : " << scrBufferInfo.dwSize.X << " x " << scrBufferInfo.dwSize.Y << endl;

return 0;
}

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

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com