设为首页 加入收藏

TOP

VC++获取屏幕大小第三篇 物理大小GetDeviceCaps 下
2014-11-23 19:09:49 】 浏览:8343
Tags:获取 屏幕 大小 第三篇 物理 GetDeviceCaps
通常大家在表示电脑、电视、手机等电子产品的屏幕大小时会使用英寸这一长度单位来描述。要注意的一点时,英寸在描述电脑、电视、手机等电子产品的屏幕大小时是指屏幕的对角线长度。
英寸(inch,缩写为in.)在荷兰语中的本意是大拇指,一英寸就是一节大拇指的长度。当然人的大拇指的长度也是长短不一的。14世纪时,英皇爱德华二世颁布了“标准合法英寸”。其规定为:从大麦穗中间选择三粒最大的麦粒并依次排成一行的长度就是一英寸。
英寸与毫米的换算关系为:
1英寸 = 25.4毫米
1毫米 = 0.03937英寸
根据这一换算公式,可以改写下《VC++获取屏幕大小第二篇物理大小GetDeviceCaps 上》中的代码,让其直接计算出屏幕是多少英寸的。改写后的代码如下:
[cpp] 、
// 获取屏幕大小 物理大小
#include
#include
#include
#include
int main()
{
printf(" 获取屏幕大小 物理大小\n");
printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");
int nScreenWidth, nScreenHeight;
HDC hdcScreen = GetDC(NULL); //获取屏幕的HDC
nScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);
nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);
printf("屏幕大小(毫米) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
printf(" 下面将屏幕大小由毫米换算到英寸\n");
const double MILLIMETRE_TO_INCH = 0.03937;
double fDiagonalLen = sqrt(nScreenHeight * nScreenHeight + nScreenWidth * nScreenWidth);
printf("屏幕对角线长为:%.2lf毫米 约 %.2lf英寸\n", fDiagonalLen, fDiagonalLen * MILLIMETRE_TO_INCH);
getch();
return 0;
}
// 获取屏幕大小 物理大小
#include
#include
#include
#include
int main()
{
printf(" 获取屏幕大小 物理大小\n");
printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");
int nScreenWidth, nScreenHeight;
HDC hdcScreen = GetDC(NULL); //获取屏幕的HDC
nScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);
nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);
printf("屏幕大小(毫米) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
printf(" 下面将屏幕大小由毫米换算到英寸\n");
const double MILLIMETRE_TO_INCH = 0.03937;
double fDiagonalLen = sqrt(nScreenHeight * nScreenHeight + nScreenWidth * nScreenWidth);
printf("屏幕对角线长为:%.2lf毫米 约 %.2lf英寸\n", fDiagonalLen, fDiagonalLen * MILLIMETRE_TO_INCH);
getch();
return 0;
}运行结果如下:
\
呵呵,本人笔记本的屏幕大小是13.64英寸即商家所称的14英寸笔记本。
根据这份代码可以发布个小程序,供其它人用来查看电脑屏幕大小。可惜由于GetDeviceCaps函数的限制,在Win7 系统下该程序检测结果不准确,WinXP系统下基本上可以正确运行。
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇VC++ 得到计算机名和用户名 GetCo.. 下一篇VC++获取屏幕大小第二篇 物理大小..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目