首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 下

2013-03-06 
VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上上一篇《VC++获取屏幕大小第一篇像素大小GetSystemMetric

VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上

    上一篇《VC++获取屏幕大小第一篇像素大小GetSystemMetrics》中介绍了使用GetSystemMetrics函数来获取屏幕的像素大小,本篇将介绍使用GetDeviceCaps函数来获取屏幕的物理大小。下面来看看GetDeviceCaps函数的用法:

函数功能:用于得到被定义的系统数据或者系统配置信息

函数原型:获取一些设备数据

HORZSIZE

               Width, in millimeters, of the physical screen.

VERTSIZE

               Height, in millimeters, of the physical screen.

http://blog.csdn.net/morewindows/article/details/8502592 

 

由GetDeviceCaps函数的介绍可知获取屏幕的物理大小非常简单,下面给出完整的源代码:

// 获取屏幕大小 物理大小 http://blog.csdn.net/morewindows/article/details/8502592#include <stdio.h>#include <windows.h>int main(){printf("    获取屏幕大小 物理大小\n");        printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");   int nScreenWidth, nScreenHeight;HDC hdcScreen = GetDC(NULL);   //获取屏幕的HDCnScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);printf("屏幕大小(毫米) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);return 0;}

程序运行结果如下所示:

 VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 下

 

 

后面一篇《VC++获取屏幕大小第三篇物理大小GetDeviceCaps下》将介绍获取屏幕的物理大小后计算屏幕对角线长度,再换算成英寸。这样可以方便大家查看自己电脑屏幕是多少英寸的,很多笔记本用户会有意外喔^_^。欢迎继续浏览。地址:http://blog.csdn.net/morewindows/article/details/8610891

 

转载请标明出处,原文地址:http://blog.csdn.net/morewindows/article/details/8502592

欢迎关注微博:http://weibo.com/MoreWindows


 

Note:  MSDN对GetDeviceCaps函数有说明:GetDeviceCaps reports info that the display driver provides. If the display driver declines to report any info, GetDeviceCaps calculates the info based on fixed calculations. If the display driver reports invalid info, GetDeviceCaps returns the invalid info. Also, if the display driver declines to report info, GetDeviceCaps might calculate incorrect info because it assumes either fixed DPI (96 DPI) or a fixed size (depending on the info that the display driver did and didn’t provide). Unfortunately, a display driver that is implemented to the Windows Display Driver Model (WDDM) (introduced in Windows Vista) causes GDI to not get the info, so GetDeviceCaps must always calculate the info.

 

热点排行
Bad Request.