如何在Linux中以编程方式获取窗口和系统的分辨率? [英] How to programmatically get the resolution of a window and that of the system in Linux?

查看:355
本文介绍了如何在Linux中以编程方式获取窗口和系统的分辨率?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Linux系统上获得屏幕的分辨率以及特定窗口(程序正在运行)的分辨率。我不需要修改分辨率,我只需要当前的值。据我所知,我们可以调用一些系统函数在Windows上这样做,我们如何在Linux上,最好是使用C / C ++语言?先感谢。



更新:实际上,我不需要做一个GUI,虽然我知道Qt和GTK +可以做到,我不愿意包括

在X11中,您需要调用Xlib的 XGetWindowAttributes 来获取各种窗口信息,包括相对于父级的大小和位置。有关如何使用它的一个例子,你可以google为'xwininfo.c'。



也就是说,你可能会使用一些更高级的框架来做你的窗口编程 - 以及它已经有一些其他原语的机会很高,请参见 Qt 的示例 - 所以你可能想给一些关于这个问题的背景。


I'm trying to get the resolution of the screen as well as the resolution of a specific window (in which a program is running) on Linux system. I don't need to modify the resolution, I only need the current values. As far as I know, we can call some system functions to do so on Windows, how can we do that on Linux, preferably using C/C++ language? Thanks in advance.

update: Actually, I don't need to do a GUI, although I know Qt and GTK+ can do it, I'm reluctant to include an external library for just getting the resolution.

解决方案

In X11, you'd need to call the Xlib's XGetWindowAttributes to get the various window info, including the size and position relative to parent. For an example of how it is used, you can google for 'xwininfo.c'.

That said, probably you are going to use some more highlevel framework to do your window programming - and the chances are high that it already has some other primitives for this, see an example for Qt - so you might want to give a bit more background about the question.

这篇关于如何在Linux中以编程方式获取窗口和系统的分辨率?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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