获取终端大小在C的窗户? [英] Getting terminal size in c for windows?

查看:110
本文介绍了获取终端大小在C的窗户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何检查ymax和XMAX在控制台窗口中,在Windows下,使用普通的C?

How to check ymax and xmax in a console window, under Windows, using plain c?

有就是这块code为Linux的:

There is this piece of code for linux:

#include <stdio.h>
#include <sys/ioctl.h>
int main (void)
{
    struct winsize max;
    ioctl(0, TIOCGWINSZ , &max);
    printf ("lines %d\n", max.ws_row);
    printf ("columns %d\n", max.ws_col);
}

现在我不知道我该怎么做同样的窗口。我试图 winioctl.h ,但它并没有定义结构使用winsize 或任何其他具有类似名称。

Now I wonder how can I do the same for windows. I tried winioctl.h but it does not define struct winsize nor any other with a similar name.

任何提示吗?谢谢你。

PS。在linux中也可以找到使用 GETENV(台词)控制台的大小; 。有没有windows下一个类似的变量?

PS. In linux you also can find the console size using getenv("LINES");. Is there a similar variable under windows?

PPS。此外,总有 ncurses.h ,我想工作的两个系统,但我避免了因与我有其他库发生冲突了。

PPS. Also, there is always ncurses.h, that I suppose work both systems, but I'm avoiding it because of conflicts with other libraries I have.

购买力平价。这里这个问题获取终端宽度C 2 有很多技巧的,所以没必要重复这一点。

PPPS. This question here Getting terminal width in C? has a lot of tips, so no need to repeat that.

推荐答案

(部分答案)

这code:

CONSOLE_SCREEN_BUFFER_INFO csbi;
int ret;
ret = GetConsoleScreenBufferInfo(GetStdHandle( STD_OUTPUT_HANDLE ),&csbi);
if(ret)
{
    printf("Console Buffer Width: %d\n", csbi.dwSize.X);
    printf("Console Buffer Height: %d\n", csbi.dwSize.Y);
}

给出的缓冲区的大小。唯一的问题是, dwSize.Y 是不是真的在屏幕(300这里,而不是25行)的大小。但 dwSize.X 匹配列的数量。只需要 WINDOWS.H 工作

Gives the size of the buffer. The only problem is that dwSize.Y is not really the size of the screen (300 here instead of 25 lines). But dwSize.X matches the column's number. Needs only windows.h to work.

这篇关于获取终端大小在C的窗户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆