有没有办法强制控制台应用程序以特定的窗口大小运行(使用 Pdcurses)?

发布于 2024-08-20 16:21:47 字数 181 浏览 5 评论 0原文

我正在尝试用 C++ 编写一个小型 Roguelike 游戏,但遇到了一个问题 - 为了让游戏正确显示,控制台窗口必须有点宽(大约 45 行,115 列) )。通过右键单击菜单栏并设置同名窗口的默认值来更改很容易,但是有没有一种方法可以从代码中自动设置它,这样我就不必要求潜在用户搞乱它?我正在使用 Pdcurses 来处理输出,如果这有帮助的话。

I'm trying my hand at throwing together a minor roguelike in C++, but I've run into a problem - in order to get the game to display correctly, the console window has to be a bit wide (around 45 rows, 115 cols). It's easy enough to change by right clicking on the menu bar and setting the defaults for windows with the same name, but is there a way I could set it automatically from the code so I don't have to ask potential users to mess with that? I'm using Pdcurses to handle output, if that helps at all.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

爺獨霸怡葒院 2024-08-27 16:21:48

IIRC,这个可以在启动游戏的快捷方式中设置,但它不是文本,我不知道使用哪些库或Windows API来修改它。这可能比尝试使用 pdcurses 更简单。

但是,不要忘记 Windows 确实有多个控制台 API。从 MSDN 中的 AllocConsole 开始了解概述,或直接跳至 ​​SetConsoleWindowInfo

IIRC, this can be set in the shortcut that launches the game, but it's not text and I don't know which libraries or Windows APIs are used to modify it. That may be simpler than trying to use pdcurses.

However, don't forget Windows does have several console APIs. Start at AllocConsole in MSDN for an overview, or skip right to SetConsoleWindowInfo.

身边 2024-08-27 16:21:48

这是一个非常老的问题,但无论如何我都会发布我的答案,以防它将来对某人有所帮助。
这就是我在 MS Windows 中使用的:

int err = system("mode con lines=45 cols=115");

我在调用 initscr(); 之前直接使用它,它的工作方式就像一个魅力。
显然,这不是很便携,但如果您在 Windows 上进行开发,它就可以发挥作用。

This is a really old question, but I'll post my answer anyway in case it helps someone in the future.
This is what I use in MS Windows:

int err = system("mode con lines=45 cols=115");

I use this directly before my call to initscr();, and it works like a charm.
This is, obviously, not very portable, but it does the trick if all you're developing on is Windows.

过期以后 2024-08-27 16:21:48

什么操作系统? (因为它是特定于操作系统的)

在 Windows 中 SetConsoleWindowInfo()

What OS? (because it is OS specific)

In Windows SetConsoleWindowInfo()

傲性难收 2024-08-27 16:21:48
    /* Resize the terminal to something larger than the physical screen */
    resize_term(2000, 2000);

    /* Get the largest physical screen dimensions */
    getmaxyx(_window, _rows, _cols);

    /* Resize so it fits */
    resize_term(_rows - 1, _cols - 1);

    /* Get the screen dimensions that fit */
    getmaxyx(_window, _rows, _cols);
    /* Resize the terminal to something larger than the physical screen */
    resize_term(2000, 2000);

    /* Get the largest physical screen dimensions */
    getmaxyx(_window, _rows, _cols);

    /* Resize so it fits */
    resize_term(_rows - 1, _cols - 1);

    /* Get the screen dimensions that fit */
    getmaxyx(_window, _rows, _cols);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文