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_CXSCREEN和SM_CYSCREEN就得到屏幕的宽和高。详见代码:

  1. //   获取屏幕大小 像素大小
  2. // By MoreWindows( http://blog.csdn.net/MoreWindows )
  3. #include <stdio.h>
  4. #include <windows.h>
  5. int main()
  6. {
  7. printf("    获取屏幕大小 像素大小\n");
  8. printf(" -- By MoreWindows( http://blog.csdn.net/MoreWindows ) --\n\n");
  9. int nScreenWidth, nScreenHeight;
  10. nScreenWidth = GetSystemMetrics(SM_CXSCREEN);
  11. nScreenHeight = GetSystemMetrics(SM_CYSCREEN);
  12. printf("屏幕大小(像素) 宽:%d 高:%d\n", nScreenWidth, nScreenHeight);
  13. return 0;
  14. }

运行结果如下:

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

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

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

转:VC++获取屏幕大小第一篇 像素大小GetSystemMetrics的更多相关文章

  1. VC获取屏幕分辨率及大小相关(转)

    vc得到屏幕的当前分辨率方法: 1.Windows API调用 int width = GetSystemMetrics ( SM_CXSCREEN );  int height= GetSystem ...

  2. js获取屏幕大小

    1.js获取屏幕大小 <html> <script> function a(){ document.write( "屏幕分辨率为:"+screen.widt ...

  3. wift - 使用UIScreen类获取屏幕大小尺寸

    UISreen类代表了屏幕,开发中一般用来获取屏幕相关的属性,例如获取屏幕的大小. 1 2 3 4 5 6 7 //获取屏幕大小 var screenBounds:CGRect = UIScreen. ...

  4. Android 获取屏幕大小和密度

    Android 获取屏幕大小和密度 DisplayMetrics metric = new DisplayMetrics(); getWindowManager().getDefaultDisplay ...

  5. cocos2d-x JS 获取屏幕大小或中点

    以一张背景图为例: var HelloWorldLayer = cc.Layer.extend({ ctor:function () { this._super(); var bg = new cc. ...

  6. Android获取屏幕大小和设置无标题栏

    android获取屏幕大小非常常用,例如写个程序,如果要做成通用性很强的程序,适用屏幕很强,一般布局的时候都是根据屏幕的长宽来定义的,所以我把这个总结一下,方便日后忘记的时候查阅.还有就是有时候写程序 ...

  7. 绘制bitmap 全屏 安卓获取 屏幕大小

    韩梦飞沙  韩亚飞  313134555@qq.com  yue31313  han_meng_fei_sha 绘制bitmap 全屏 Rectf rectF = new RectF(0, 0, w, ...

  8. C#获取屏幕大小或任务栏大小

    C#获取屏幕大小或任务栏大小http://www.cnblogs.com/chlyzone/archive/2012/11/05/2754601.html

  9. [linux][c++]linux c++ 通过xcb库获取屏幕大小

    linux c++ 通过xcb库获取屏幕大小 #include <stdio.h> #include <xcb/xcb.h> /** clang++ main.cpp -o m ...

随机推荐

  1. 第1章 Python介绍

    本章将包含Python的介绍,安装以及Python的数据类型及运算符.其中关于数据类型中的字符串.列表.元组和字典后续章节会着重介绍. 1.1 为什么学Python Python是一门简明并强大的面向 ...

  2. JS~js里实现队列与堆栈

    在面向对象的程序设计里,一般都提供了实现队列(queue)和堆栈(stack)的方法,而对于JS来说,我们可以实现数组的相关操作,来实现队列和堆栈的功能,看下面的相关介绍. 一 看一下它们的性质,这种 ...

  3. HTML5 Canvas渐进填充与透明

    详细解释HTML5 Canvas中渐进填充的参数设置与使用,Canvas中透明度的设置与使 用,结合渐进填充与透明度支持,实现图像的Mask效果. 一:渐进填充(Gradient Fill) Canv ...

  4. Unity3D——窗体介绍

    这是本人第一次的Unity的博客,主要还是依据雨松MOMO的视频来进行的,由于感觉视频比較直观,对于入门比較快,再加上自己有对应的编程基础,如今看书的话效率不高,所以先看几个视频了解一下大体的流程,感 ...

  5. 573 The Snail(蜗牛)

      The Snail  A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can ...

  6. [Angular 2] Mapping Streams to Values to Affect State

    While you have multiple streams flowing into your scan operator, you'll need to map each stream to t ...

  7. UCOS 中的中断处理

    最近遇到一个问题,当我在UCOS里调用系统延时"OSTimeDlyHMSM(0, 0, 0, 10)",程序进入硬件错误中断“HardFault_Handler”中. 我开始以为是 ...

  8. 从JPG中获取缩略图

    using System; using System.Drawing; using System.Collections; using System.ComponentModel; using Sys ...

  9. 注意在insert插入数据库时的int类型问题

    比如,一个语句,insert into mbProduct(p_UserID,p_BigID,p_qq)values("+getUserid+",'"+getdrpdl+ ...

  10. (转)\r \r\n \t 的区别

    小风吹雪 \r \r\n \t 的区别 http://www.360doc.com/content/12/0530/15/16538_214756101.shtml \n 软回车:       在Wi ...