zoukankan      html  css  js  c++  java
  • Linux 获取屏幕分辨率与窗口行列数(c/c++)

    获取当前分辨率

    #include<stdio.h>
    #include<sys/types.h>
    #include<sys/stat.h>
    #include<sys/mman.h>
    #include<sys/ioctl.h>
    #include<unistd.h>
    #include<fcntl.h>
    #include<linux/fb.h>
    
    int main(int argc,char *argv[]){
        int fd;                                                                              
        struct fb_var_screeninfo screen_info;
        fd = open("/dev/fb0",O_RDWR);
        ioctl(fd,FBIOGET_VSCREENINFO,&screen_info);
        printf("%d*%d
    ",screen_info.xres,screen_info.yres);
        close(fd);
        return 0;
    }
    

    结果:

    root@cocktail:~# vim screen_xy.c 
    root@cocktail:~# ./screen_xy 
    1152*864
    root@cocktail:~# 
    

    获取当前窗口大小

    这里大小指的是一个满屏幕的窗口,按照当前字体大小所能显示的字体的行数与列数。
    如果调整字体大小,结果会根据字体大小变化。这一结论在ssh工具界面也适用。

    #include<stdio.h>
    #include<stdlib.h>
    #include<sys/ioctl.h>
    #include<termios.h>
    #include<signal.h>
    #include<unistd.h>
    
    int main(int argc,char *argv[]){                                                         
        struct winsize info;
        ioctl(STDIN_FILENO,TIOCGWINSZ,&info);
        printf("当前终端为%d行%d列
    ",info.ws_row,info.ws_col);
        return 0;
    }
    

    结论:

    root@cocktail:~# vim screen_wc.c 
    root@cocktail:~# ./screen_wc
    当前终端为23行89列
    root@cocktail:~# 
    
  • 相关阅读:
    #1015 : KMP算法
    #1014 Trie树
    Type.IsContextful 说明
    判断.net中在windows系统下的字节序
    Python3 循环语句
    adb 脚本
    如何使用 adb 命令实现自动化测试
    python 字符串的方法和注释
    Android使用Fiddler模拟弱网络环境测试
    Android定位元素与操作
  • 原文地址:https://www.cnblogs.com/sinpo828/p/10678945.html
Copyright © 2011-2022 走看看