获取屏幕大小

来源:互联网 发布:apache 监控 插件 编辑:程序博客网 时间:2024/04/24 15:19

屏幕的大小有两种情形:

(1)整个屏幕的大小,包括工具栏的大小。方法是用函数

int WINAPI GetSystemMetrics(  __in          int nIndex);
用法:
int xScreen = GetSystemMetrics(SM_CXFULLSCREEN); // screen width
int yScreen = GetSystemMetrics(SM_CYFULLSCREEN); // screen heigth
(2)work屏幕的大小,不包括工具栏的大小。方法是用函数
BOOL WINAPI SystemParametersInfo(  __in          UINT uiAction,  __in          UINT uiParam,  __in_out      PVOID pvParam,  __in          UINT fWinIni);

用法:
RECT rtChange = {0};SystemParametersInfo(SPI_GETWORKAREA,     0,  &rtChange,     0);


In code:

using System.Runtime.InteropServices; // using声明

// 函数声明
[DllImport("user32")]
public static extern int GetSystemMetrics(
int nIndex
);



语法

  int WINAPI GetSystemMetrics( __in int nIndex);   下面是GetSystemMetrics函数参数nIndex的定义:  SM_ARRANGE 标志用于说明系统如何安排最小化窗口..详细请参看下方备注.:  根据显示器显示的不同,系统数据可能有所不同.   该SM_ARRANGE设置指定系统如何安排最小化窗口,并包含一个起始位置和方向。起始位置可为下列值之一.  ValueMeaningARW_BOTTOMLEFT开始在左下角的屏幕(默认位置) 。ARW_BOTTOMRIGHT开始在右下角的屏幕上。相当于ARW_STARTRIGHT.ARW_HIDE在屏幕可见区域,隐藏并最小化窗口。.ARW_TOPLEFT从左上角的屏幕上。相当于ARV_STARTTOP.ARW_TOPRIGHT开始在右上角的在屏幕上。相当于ARW_STARTTOP | SRW_STARTRIGHT 。  方向的安排可以为下列值之一。  ValueMeaningARW_DOWN纵向排列,从上到下。ARW_LEFT水平排列,从左到右。ARW_RIGHT水平排列,从右到左。ARW_UP纵向排列,从下到上。  SM_CLEANBOOT 返回系统启动方式   0 正常启动  1 安全模式启动  2 网络安全模式启动  SM_CMOUSEBUTTONS 返回值为系统支持的鼠标键数,返回0,则系统中没有安装鼠标。  SM_CXBORDER,  SM_CYBORDER 返回以像素值为单位的Windows窗口边框的宽度和高度,如果Windows的为3D形态,则  等同于SM_CXEDGE参数  SM_CXCURSOR,  SM_CYCURSOR 返回以像素值为单位的标准光标的宽度和高度  SM_CXDLGFRAME,  SM_CYDLGFRAME 等同与SM_CXFIXEDFRAME and SM_CYFIXEDFRAME  SM_CXDOUBLECLK,  SM_CYDOUBLECLK 以像素值为单位的双击有效的矩形区域  SM_CXEDGE,SM_CYEDGE 以像素值为单位的3D边框的宽度和高度  SM_CXFIXEDFRAME,  SM_CYFIXEDFRAME 围绕具有标题但无法改变尺寸的窗口(通常是一些对话框)的边框的厚度  SM_CXFRAME,SM_CYFRAME 等同于SM_CXSIZEFRAME and SM_CYSIZEFRAME  SM_CXFULLSCREEN,  SM_CYFULLSCREEN 全屏幕窗口的窗口区域的宽度和高度  SM_CXHSCROLL,  SM_CYHSCROLL 水平滚动条的高度和水平滚动条上箭头的宽度  SM_CXHTHUMB 以像素为单位的水平滚动条上的滑动块宽度  SM_CXICON,SM_CYICON 系统缺省的图标的高度和宽度(一般为32*32)  SM_CXICONSPACING,  SM_CYICONSPACING 以大图标方式查看Item时图标之间的间距,这个距离总是大于等于  SM_CXICON and SM_CYICON.  SM_CXMAXIMIZED,  SM_CYMAXIMIZED 处于顶层的最大化窗口的缺省尺寸  SM_CXMAXTRACK,  SM_CYMAXTRACK 具有可改变尺寸边框和标题栏的窗口的缺省最大尺寸,如果窗口大于这个  尺寸,窗口是不可移动的。  SM_CXMENUCHECK,  SM_CYMENUCHECK 以像素为单位计算的菜单选中标记位图的尺寸  SM_CXMENUSIZE,  SM_CYMENUSIZE 以像素计算的菜单栏按钮的尺寸  SM_CXMIN,SM_CYMIN 窗口所能达到的最小尺寸  SM_CXMINIMIZED,  SM_CYMINIMIZED 正常的最小化窗口的尺寸  SM_CXMINTRACK,  SM_CYMINTRACK 最小跟踪距离,当使用者拖动窗口移动距离小于这个值,窗口不会移动。  SM_CXSCREEN,  SM_CYSCREEN 以像素为单位计算的屏幕尺寸。  SM_CXSIZE,SM_CYSIZE 以像素计算的标题栏按钮的尺寸  SM_CXSIZEFRAME,  SM_CYSIZEFRAME 围绕可改变大小的窗口的边框的厚度  SM_CXSMICON,  SM_CYSMICON 以像素计算的小图标的尺寸,小图标一般出现在窗口标题栏上。  SM_CXVSCROLL,  SM_CYVSCROLL 以像素计算的垂直滚动条的宽度和垂直滚动条上箭头的高度  SM_CYCAPTION 以像素计算的普通窗口标题的高度  SM_CYMENU 以像素计算的单个菜单条的高度  SM_CYSMCAPTION 以像素计算的窗口小标题栏的高度  SM_CYVTHUMB 以像素计算的垂直滚动条中滚动块的高度  SM_DBCSENABLED 如果为TRUE或不为0的值表明系统安装了双字节版本的USER.EXE,为FALSE或0则不是。  SM_DEBUG 如果为TRUE或不为0的值表明系统安装了debug版本的USER.EXE,为FALSE或0则不是。  SM_MENUDROPALIGNMENT 如果为TRUE或不为0的值下拉菜单是右对齐的否则是左对齐的。  SM_MOUSEPRESENT 如果为TRUE或不为0的值则安装了鼠标,否则没有安装。  SM_MOUSEWHEELPRESENT 如果为TRUE或不为0的值则安装了滚轮鼠标,否则没有安装。(Windows NT only)  SM_SWAPBUTTON 如果为TRUE或不为0的值则鼠标左右键交换,否则没有。

编辑本段index值

  SM_CXSCREEN = 0 'X Size of screen  SM_CYSCREEN = 1 'Y Size of Screen  SM_CXVSCROLL = 2 'X Size of arrow in vertical scroll bar.  SM_CYHSCROLL = 3 'Y Size of arrow in horizontal scroll bar  SM_CYCAPTION = 4 'Height of windows caption  SM_CXBORDER = 5 'Width of no-sizable borders  SM_CYBORDER = 6 'Height of non-sizable borders  SM_CXDLGFRAME = 7 'Width of dialog box borders  SM_CYDLGFRAME = 8 'Height of dialog box borders  SM_CYHTHUMB = 9 'Height of scroll box on horizontal scroll bar  SM_CXHTHUMB = 10 ' Width of scroll box on horizontal scroll bar  SM_CXICON = 11 'Width of standard icon  SM_CYICON = 12 'Height of standard icon  SM_CXCURSOR = 13 'Width of standard cursor  SM_CYCURSOR = 14 'Height of standard cursor  SM_CYMENU = 15 'Height of menu  SM_CXFULLSCREEN = 16 'Width of client area of maximized window  SM_CYFULLSCREEN = 17 'Height of client area of maximized window  SM_CYKANJIWINDOW = 18 'Height of Kanji window  SM_MOUSEPRESENT = 19 'True is a mouse is present  SM_CYVSCROLL = 20 'Height of arrow in vertical scroll bar  SM_CXHSCROLL = 21 'Width of arrow in vertical scroll bar  SM_DEBUG = 22 'True if deugging version of windows is running  SM_SWAPBUTTON = 23 'True if left and right buttons are swapped.  SM_CXMIN = 28 'Minimum width of window  SM_CYMIN = 29 'Minimum height of window  SM_CXSIZE = 30 'Width of title bar bitmaps  SM_CYSIZE = 31 'height of title bar bitmaps  SM_CXMINTRACK = 34 'Minimum tracking width of window  SM_CYMINTRACK = 35 'Minimum tracking height of window  SM_CXDOUBLECLK = 36 'double click width  SM_CYDOUBLECLK = 37 'double click height  SM_CXICONSPACING = 38 'width between desktop icons  SM_CYICONSPACING = 39 'height between desktop icons  SM_MENUDROPALIGNMENT = 40 'Zero if popupmenus are aligned to the left of the memu bar item. True if it isaligned to the right.  SM_PENWINDOWS = 41 'The handle of the pen windows DLL if loaded.  SM_DBCSENABLED = 42 'True if double byte characteds are enabled  SM_CMOUSEBUTTONS = 43 'Number of mouse buttons.  SM_CMETRICS = 44 'Number of system metrics  SM_CLEANBOOT = 67 'Windows 95 boot mode. 0 = normal, 1 = safe, 2 = safe with network  SM_CXMAXIMIZED = 61 'default width of win95 maximised window  SM_CXMAXTRACK = 59 'maximum width when resizing win95 windows  SM_CXMENUCHECK = 71 'width of menu checkmark bitmap  SM_CXMENUSIZE = 54 'width of button on menu bar  SM_CXMINIMIZED = 57 'width of rectangle into which minimised windows must fit.  SM_CYMAXIMIZED = 62 'default height of win95 maximised window  SM_CYMAXTRACK = 60 'maximum width when resizing win95 windows  SM_CYMENUCHECK = 72 'height of menu checkmark bitmap  SM_CYMENUSIZE = 55 'height of button on menu bar  SM_CYMINIMIZED = 58 'height of rectangle into which minimised windows must fit.  SM_CYSMCAPTION = 51 'height of windows 95 small caption  SM_MIDEASTENABLED = 74 'Hebrw and Arabic enabled for windows 95  SM_NETWORK = 63 'bit o is set if a network is present.   SM_SECURE = 44 'True if security is present on windows 95 system  SM_SLOWMACHINE = 73 'true if machine is too slow to run win95.

原创粉丝点击