VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
来源:互联网 发布:mac qq不能截图 编辑:程序博客网 时间:2024/05/24 05:23
上一篇《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); //获取屏幕的HDCnScreenWidth = 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.
- VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- 获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- VC++获取屏幕大小第三篇 物理大小GetDeviceCaps 下
- VC++获取屏幕大小第三篇 物理大小GetDeviceCaps 下
- VC++获取屏幕大小第三篇 物理大小GetDeviceCaps 下
- 获取屏幕大小第三篇 物理大小GetDeviceCaps 下(英寸和像素转换-2540)
- vc 获取屏幕大小
- vc 获取屏幕大小
- VC++获取屏幕大小第一篇 像素大小GetSystemMetrics
- VC++获取屏幕大小第一篇 像素大小 GetSystemMetrics
- VC++获取屏幕大小第一篇 像素大小GetSystemMetrics
- 获取屏幕信息GetDeviceCaps
- vc获得屏幕大小
- vc获得屏幕大小
- VC MFC 获取屏幕大小 程序窗口大小位置 控件大小位置
- 获取屏幕大小
- jdbc实现篇-源码(Oracle、MySQL)-第一部分-Dirver注册和获取及Connection获取原理
- Java学习笔记(事件,内部类)
- JUnit4 详解
- Java web 开发入门
- hdu1163
- VC++获取屏幕大小第二篇 物理大小GetDeviceCaps 上
- git ---介绍
- common and different of final in java and const in C++
- 调试程序
- VC2008中使用GDI+ (VC6也差不多)
- 基础加强_类加载器,类的加载机制
- 百练 2882 Problem I
- 游戏专有名词
- /dev/tty /dev/ttyS0 /dev/tty0区别