正在阅读:Windows API-GDI入门基础知识详解(2)Windows API-GDI入门基础知识详解(2)

2005-06-30 10:06 出处:PConline 作者:管宁 责任编辑:xietaoming

字符大小

  如果要使用TextOut函数显示多行文字,那么就必须确定字体字符的大小,字体的高度确定了下一行字符的显示位置,字体的宽度确定了下一列的显示位置。

  屏幕的分辨率和字符大小是确定如何显示字符的主要依据,为了获得当前系统上各种与视觉属性相关的信息,我们可以调用GetSystemMetrics函数获取,调用GetTextMetrics函数可以获取字体大小。

  以下是这两个函数的原形以及参数的详细定义:

int GetSystemMetrics(

  int nIndex  // 索引

);

  GetSystemMetrics函数是完成Windows图形输出的重要函数,它返回Windows中各种与视觉属性相关的信息,该函数需要只需要一个参数,它是一个索引,这些索引是在Windows头文件中定义的一些常量,这些常量分别指定了不同的与视觉相关的设备属性,这些索引的多少取决与Windows的版本。

  以下是这些索引的含义:

Value Meaning
SM_ARRANGE Flags specifying how the system arranged minimized windows. For more information about minimized windows, see the following Remarks section.
SM_CLEANBOOT Value that specifies how the system was started: 0 Normal boot
1 Fail-safe boot
2 Fail-safe with network boot
Fail-safe boot (also called SafeBoot, Safe Mode, or Clean Boot) bypasses the user's startup files.
SM_CMONITORS Number of display monitors on the desktop. See Remarks for more information. Windows NT, Windows 95:  This value is not supported.
SM_CMOUSEBUTTONS Number of buttons on mouse, or zero if no mouse is installed.
SM_CXBORDER, SM_CYBORDER Width and height of a window border, in pixels. This is equivalent to the SM_CXEDGE value for windows with the 3-D look.
SM_CXCURSOR, SM_CYCURSOR Width and height of a cursor, in pixels. The system cannot create cursors of other sizes.
SM_CXDLGFRAME, SM_CYDLGFRAME Same as SM_CXFIXEDFRAME and SM_CYFIXEDFRAME.
SM_CXDOUBLECLK, SM_CYDOUBLECLK Width and height of the rectangle around the location of a first click in a double-click sequence, in pixels. The second click must occur within this rectangle for the system to consider the two clicks a double-click. (The two clicks must also occur within a specified time.) To set the width and height of the double-click rectangle, call SystemParametersInfo with the SPI_SETDOUBLECLKHEIGHT and SPI_SETDOUBLECLKWIDTH flags.
SM_CXDRAG, SM_CYDRAG Width and height of a rectangle centered on a drag point to allow for limited movement of the mouse pointer before a drag operation begins. These values are in pixels. It allows the user to click and release the mouse button easily without unintentionally starting a drag operation.
SM_CXEDGE, SM_CYEDGE Dimensions of a 3-D border, in pixels. These are the 3-D counterparts of SM_CXBORDER and SM_CYBORDER.
SM_CXFIXEDFRAME, SM_CYFIXEDFRAME Thickness of the frame around the perimeter of a window that has a caption but is not sizable, in pixels. SM_CXFIXEDFRAME is the height of the horizontal border and SM_CYFIXEDFRAME is the width of the vertical border. Same as SM_CXDLGFRAME and SM_CYDLGFRAME.
SM_CXFOCUSBORDER, SM_CYFOCUSBORDER Width of the left and right edges and the height of the top and bottom edges of the focus rectangle drawn by DrawFocusRect. These values are in pixels. Windows 2000/NT, Windows Me/98/95:  This value is not supported.
SM_CXFRAME, SM_CYFRAME Same as SM_CXSIZEFRAME and SM_CYSIZEFRAME.
SM_CXFULLSCREEN, SM_CYFULLSCREEN Width and height of the client area for a full-screen window on the primary display monitor, in pixels. To get the coordinates of the portion of the screen not obscured by the system taskbar or by application desktop toolbars, call the SystemParametersInfo function with the SPI_GETWORKAREA value.
SM_CXHSCROLL, SM_CYHSCROLL Width of the arrow bitmap on a horizontal scroll bar, in pixels; and height of a horizontal scroll bar, in pixels.
SM_CXHTHUMB Width of the thumb box in a horizontal scroll bar, in pixels.
SM_CXICON, SM_CYICON Default width and height of an icon, in pixels. The LoadIcon function can load only icons of these dimensions.
SM_CXICONSPACING, SM_CYICONSPACING Dimensions of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of this size when arranged. These values are always greater than or equal to SM_CXICON and SM_CYICON.
SM_CXMAXIMIZED, SM_CYMAXIMIZED Default dimensions, in pixels, of a maximized top-level window on the primary display monitor.
SM_CXMAXTRACK, SM_CYMAXTRACK Default maximum dimensions of a window that has a caption and sizing borders, in pixels. This metric refers to the entire desktop. The user cannot drag the window frame to a size larger than these dimensions. A window can override these values by processing the WM_GETMINMAXINFO message.
SM_CXMENUCHECK, SM_CYMENUCHECK Dimensions of the default menu check-mark bitmap, in pixels.
SM_CXMENUSIZE, SM_CYMENUSIZE Dimensions of menu bar buttons, such as the child window close button used in the multiple document interface, in pixels.
SM_CXMIN, SM_CYMIN Minimum width and height of a window, in pixels.
SM_CXMINIMIZED, SM_CYMINIMIZED Dimensions of a minimized window, in pixels.
SM_CXMINSPACING SM_CYMINSPACING Dimensions of a grid cell for a minimized window, in pixels. Each minimized window fits into a rectangle this size when arranged. These values are always greater than or equal to SM_CXMINIMIZED and SM_CYMINIMIZED.
SM_CXMINTRACK, SM_CYMINTRACK Minimum tracking width and height of a window, in pixels. The user cannot drag the window frame to a size smaller than these dimensions. A window can override these values by processing the WM_GETMINMAXINFO message.
SM_CXSCREEN, SM_CYSCREEN Width and height of the screen of the primary display monitor, in pixels. These are the same values obtained by calling GetDeviceCaps(hdcPrimaryMonitor, HORZRES/VERTRES).
SM_CXSIZE, SM_CYSIZE Width and height of a button in a window's caption or title bar, in pixels.
SM_CXSIZEFRAME, SM_CYSIZEFRAME Thickness of the sizing border around the perimeter of a window that can be resized, in pixels. SM_CXSIZEFRAME is the width of the horizontal border, and SM_CYSIZEFRAME is the height of the vertical border. Same as SM_CXFRAME and SM_CYFRAME.
SM_CXSMICON, SM_CYSMICON Recommended dimensions of a small icon, in pixels. Small icons typically appear in window captions and in small icon view.
SM_CXSMSIZE SM_CYSMSIZE Dimensions of small caption buttons, in pixels.
SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN Width and height of the virtual screen, in pixels. The virtual screen is the bounding rectangle of all display monitors. The SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN metrics are the coordinates of the top-left corner of the virtual screen. Windows NT, Windows 95:  This value is not supported.
SM_CXVSCROLL, SM_CYVSCROLL Width of a vertical scroll bar, in pixels; and height of the arrow bitmap on a vertical scroll bar, in pixels.
SM_CYCAPTION Height of a caption area, in pixels.
SM_CYKANJIWINDOW For double byte character set versions of the system, this is the height of the Kanji window at the bottom of the screen, in pixels.
SM_CYMENU Height of a single-line menu bar, in pixels.
SM_CYSMCAPTION Height of a small caption, in pixels.
SM_CYVTHUMB Height of the thumb box in a vertical scroll bar, in pixels.
SM_DBCSENABLED TRUE or nonzero if User32.dll supports DBCS; FALSE or zero otherwise. Windows Me/98/95:   TRUE or nonzero if the double-byte character-set (DBCS) version of User.exe is installed; FALSE or zero otherwise.
SM_DEBUG TRUE or nonzero if the debug version of User.exe is installed; FALSE or zero otherwise.
SM_IMMENABLED TRUE or nonzero if Input Method Manager/Input Method Editor features are enabled; FALSE or zero otherwise. Windows NT, Windows Me/98/95:  This value is not supported. SM_IMMENABLED indicates whether the system is ready to use a Unicode-based IME on a Unicode application. To ensure that a language-dependent IME works, check SM_DBCSENABLED and the system ANSI code page. Otherwise the ANSI-to-Unicode conversion may not be performed correctly, or some components like fonts or registry setting may not be present.
SM_MENUDROPALIGNMENT TRUE or nonzero if drop-down menus are right-aligned with the corresponding menu-bar item; FALSE or zero if the menus are left-aligned.
SM_MIDEASTENABLED TRUE if the system is enabled for Hebrew and Arabic languages.
SM_MOUSEPRESENT TRUE or nonzero if a mouse is installed; FALSE or zero otherwise.
SM_MOUSEWHEELPRESENT TRUE or nonzero if a mouse with a wheel is installed; FALSE or zero otherwise. Windows 3.51 and earlier, Windows 95:  This value is not supported.
SM_NETWORK Least significant bit is set if a network is present; otherwise, it is cleared. The other bits are reserved for future use.
SM_PENWINDOWS TRUE or nonzero if the Microsoft Windows for Pen computing extensions are installed; FALSE or zero otherwise.
SM_REMOTECONTROL This system metric is used in a Terminal Services environment. Its value is TRUE if the current session is remotely controlled; FALSE otherwise. Windows 2000/NT, Windows Me/98/95:  This value is not supported.
SM_REMOTESESSION This system metric is used in a Terminal Services environment. If the calling process is associated with a Terminal Services client session, the return value is TRUE or nonzero. If the calling process is associated with the Terminal Server console session, the return value is zero. Windows NT 4.0 SP3 and earlier, Windows Me/98/95:  This value is not supported.
SM_SECURE TRUE if security is present; FALSE otherwise.
SM_SAMEDISPLAYFORMAT TRUE if all the display monitors have the same color format, FALSE otherwise. Note that two displays can have the same bit depth, but different color formats. For example, the red, green, and blue pixels can be encoded with different numbers of bits, or those bits can be located in different places in a pixel's color value. Windows NT, Windows 95:  This value is not supported.
SM_SHOWSOUNDS TRUE or nonzero if the user requires an application to present information visually in situations where it would otherwise present the information only in audible form; FALSE, or zero, otherwise.
SM_SHUTTINGDOWN TRUE if the current session is shutting down; FALSE otherwise. Windows 2000/NT, Windows Me/98/95:  This value is not supported.
SM_SLOWMACHINE TRUE if the computer has a low-end (slow) processor; FALSE otherwise.
SM_SWAPBUTTON TRUE or nonzero if the meanings of the left and right mouse buttons are swapped; FALSE or zero otherwise.
SM_XVIRTUALSCREEN, SM_YVIRTUALSCREEN Coordinates for the left side and the top of the virtual screen. The virtual screen is the bounding rectangle of all display monitors. The SM_CXVIRTUALSCREEN, SM_CYVIRTUALSCREEN metrics are the width and height of the virtual screen. Windows NT, Windows 95:  This value is not supported.

键盘也能翻页,试试“← →”键

关注我们

最新资讯离线随时看 聊天吐槽赢奖品