当前位置:编程学习 > VC++ >>

VC++获取屏幕大小第二篇 物理大小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函数的介绍可知获取屏幕的物理大小非常简单,下面给出完整的源代码:
 
[cpp]
// 获取屏幕大小 物理大小 <A href="http://blog.csdn.net/morewindows/article/details/8502592">http://blog.csdn.net/morewindows/article/details/8502592</A>   
#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;  
}  
 
// 获取屏幕大小 物理大小 http://blog.csdn.net/morewindows/article/details/8502592
#include <stdio.h>
#include <windows.h>
int main()
{ www.zzzyk.com
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 ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,