VC++获取屏幕大小第一篇 像素大小GetSystemMetrics

    《VC++获取屏幕大小第一篇 像素大小 GetSystemMetrics》和《VC++获取屏幕大小第二篇物理大小GetDeviceCaps 》和《VC++获取屏幕大小第三篇物理大小GetDeviceCaps》这三篇文章主要讲解在VC++下获取屏幕大小。这个功能非常简单,也比较实用。

 

    要获取屏幕的像素大小要使用GetSystemMetrics函数。下面就来看看这个函数的用法:

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

函数原型:

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

int WINAPIGetSystemMetrics(

       int nIndex

);

参数说明:

这个函数只有一个参数,不过这个参数可以取很多值。在WINUSER.H中有:

/*

 * GetSystemMetrics() codes

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

 */

#define SM_CXSCREEN             0

#define SM_CYSCREEN             1

#define SM_CXVSCROLL            2

#define SM_CYHSCROLL            3

#define SM_CYCAPTION            4

#define SM_CXBORDER             5

#define SM_CYBORDER             6

#define SM_CXDLGFRAME           7

#define SM_CYDLGFRAME           8

#define SM_CYVTHUMB             9

#define SM_CXHTHUMB             10

#define SM_CXICON               11

#define SM_CYICON               12

#define SM_CXCURSOR             13

#define SM_CYCURSOR             14

#define SM_CYMENU               15

#define SM_CXFULLSCREEN         16

#define SM_CYFULLSCREEN         17

#define SM_CYKANJIWINDOW        18

#define SM_MOUSEPRESENT         19

#define SM_CYVSCROLL            20

#define SM_CXHSCROLL            21

#define SM_DEBUG                22

#define SM_SWAPBUTTON           23

#define SM_RESERVED1            24

#define SM_RESERVED2            25

#define SM_RESERVED3            26

#define SM_RESERVED4            27

#define SM_CXMIN                28

#define SM_CYMIN                29

#define SM_CXSIZE               30

#define SM_CYSIZE               31

#define SM_CXFRAME              32

#define SM_CYFRAME              33

#define SM_CXMINTRACK           34

#define SM_CYMINTRACK           35

#define SM_CXDOUBLECLK          36

#define SM_CYDOUBLECLK          37

#define SM_CXICONSPACING        38

#define SM_CYICONSPACING        39

#define SM_MENUDROPALIGNMENT    40

#define SM_PENWINDOWS           41

#define SM_DBCSENABLED          42

#define SM_CMOUSEBUTTONS        43

 

#if(WINVER >= 0x0400)

#define SM_CXFIXEDFRAME           SM_CXDLGFRAME  /* ;win40 name change */

#define SM_CYFIXEDFRAME           SM_CYDLGFRAME  /* ;win40 name change */

#define SM_CXSIZEFRAME            SM_CXFRAME     /* ;win40 name change */

#define SM_CYSIZEFRAME            SM_CYFRAME     /* ;win40 name change */

 

#define SM_SECURE               44

#define SM_CXEDGE               45

#define SM_CYEDGE               46

#define SM_CXMINSPACING         47

#define SM_CYMINSPACING         48

#define SM_CXSMICON             49

#define SM_CYSMICON             50

#define SM_CYSMCAPTION          51

#define SM_CXSMSIZE             52

#define SM_CYSMSIZE             53

#define SM_CXMENUSIZE           54

#define SM_CYMENUSIZE           55

#define SM_ARRANGE              56

#define SM_CXMINIMIZED          57

#define SM_CYMINIMIZED          58

#define SM_CXMAXTRACK           59

#define SM_CYMAXTRACK           60

#define SM_CXMAXIMIZED          61

#define SM_CYMAXIMIZED          62

#define SM_NETWORK              63

#define SM_CLEANBOOT            67

#define SM_CXDRAG               68

#define SM_CYDRAG               69

#endif /* WINVER >= 0x0400 */

#define SM_SHOWSOUNDS           70

#if(WINVER >= 0x0400)

#define SM_CXMENUCHECK          71   /* Use instead of GetMenuCheckMarkDimensions()! */

#define SM_CYMENUCHECK          72

#define SM_SLOWMACHINE          73

#define SM_MIDEASTENABLED       74

#endif /* WINVER >= 0x0400 */

#if (WINVER >= 0x0500) || (_WIN32_WINNT >= 0x0400)

#define SM_MOUSEWHEELPRESENT    75

#endif

#if(WINVER >= 0x0500)

#define SM_XVIRTUALSCREEN       76

#define SM_YVIRTUALSCREEN       77

#define SM_CXVIRTUALSCREEN      78

#define SM_CYVIRTUALSCREEN      79

#define SM_CMONITORS            80

#define SM_SAMEDISPLAYFORMAT    81

#endif /* WINVER >= 0x0500 */

 

#if (WINVER < 0x0500) && (!defined(_WIN32_WINNT) || (_WIN32_WINNT < 0x0400))

#define SM_CMETRICS             76

#else

#define SM_CMETRICS             83

#endif

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

 

呵呵,够多吧,不用记,要用的时候查下MSDN就好了。由MSDN可以知道传入SM_CXSCREENSM_CYSCREEN就得到屏幕的宽和高。详见代码:

//   获取屏幕大小 像素大小
// By MoreWindows( http://blog.csdn.net/MoreWindows )
#include <stdio.h>
#include <windows.h>
int main()
{
	printf("    获取屏幕大小 像素大小\n");        
	printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");   

	int nScreenWidth, nScreenHeight;
	nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
	nScreenHeight = GetSystemMetrics(SM_CYSCREEN);

	printf("屏幕大小(像素) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
	return 0;
}

运行结果如下:

 

后面二篇《VC++获取屏幕大小第二篇物理大小GetDeviceCaps》和《VC++获取屏幕大小第三篇物理大小GetDeviceCaps》将介绍使用GetDeviceCaps函数来获取屏幕的物理大小,欢迎继续浏览。

地址1:http://blog.csdn.net/morewindows/article/details/8502592

地址2:http://blog.csdn.net/morewindows/article/details/8610891

 

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

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


 

  • 4
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值