Fork me on GitHub

获取屏幕分辨率

方法一、使用GetSystemMetrics函数

GetSystemMetrics函数原型如下:

int WINAPI GetSystemMetrics(  __in  int nIndex);

每一个想要获取的信息对应着一个索引值,把索引值作为参数传递给GetSystemMetrics,将获得对应的信息。其中SM_CXSCREEN、SM_CYSCREEN分别对应获取屏幕的宽度和高度(以像素为单位)。

 int wideScreen=GetSystemMetrics(SM_CXSCREEN);
 int highScreen=GetSystemMetrics(SM_CYSCREEN);
 if (wideScreen==0||highScreen==0)
 {
      printf("Cannot get the resolution!\n");
 } 
 else
 {
      printf("The screen resolution  is %dx%d",wideScreen,highScreen);
 }

 

posted on 2015-09-22 15:53  地精的贪婪  阅读(272)  评论(0编辑  收藏  举报