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

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

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

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

// By MoreWindows( http://blog.csdn.net/MoreWindows )  

int GetDeviceCaps(

       HDChdc,     // handle to DC

       int nIndex   // index of capability

);

参数说明:

第一个参数表示设备环境的HDC句柄。

第二个参数与GetSystemMetrics函数的参数类似,有很多种取值,这里就不一一列举了,常用的有二个:

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);   //获取屏幕的HDC
	nScreenWidth = GetDeviceCaps(hdcScreen, HORZSIZE);
	nScreenHeight = GetDeviceCaps(hdcScreen, VERTSIZE);
	
	printf("屏幕大小(毫米) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
	return 0;
}

程序运行结果如下所示:

 

 

 

后面一篇《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.

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值