GetSystemMetrics (user32)
Last changed: -24.226.54.84

.
Summary

The GetSystemMetrics function retrieves various system metrics (widths and heights of display elements) and system configuration settings. All dimensions retrieved by GetSystemMetrics are in pixels.

C# Signature:

    [DllImport("user32.dll")]
    static extern int GetSystemMetrics(SystemMetric smIndex);

User-Defined Types:

http://pinvoke.net/default.aspx/Enums.SystemMetric

(commented C# signature by ai_productions@verizon.net)

    public enum SystemMetric:int
    {
        SM_CXSCREEN=0,          // Width of the screen of the primary display monitor, in pixels. This is the same values obtained by calling GetDeviceCaps as follows: GetDeviceCaps( hdcPrimaryMonitor, HORZRES).
        SM_CYSCREEN=1,          // Height of the screen of the primary display monitor, in pixels. This is the same values obtained by calling GetDeviceCaps as follows: GetDeviceCaps( hdcPrimaryMonitor, VERTRES).
        SM_CYVSCROLL=2,         // Width of a horizontal scroll bar, in pixels.
        SM_CYHSCROLL=3,         // Height of a horizontal scroll bar, in pixels.
        SM_CYCAPTION=4,         // Height of a caption area, in pixels.
        SM_CXBORDER=5,          // Width of a window border, in pixels. This is equivalent to the SM_CXEDGE value for windows with the 3-D look.
        SM_CYBORDER=6,          // Height of a window border, in pixels. This is equivalent to the SM_CYEDGE value for windows with the 3-D look.
        SM_CXDLGFRAME=7,        // 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.
        SM_CYDLGFRAME=8,        // 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.
        SM_CYVTHUMB=9,          // Height of the thumb box in a vertical scroll bar, in pixels
        SM_CXHTHUMB=10,         // Width of the thumb box in a horizontal scroll bar, in pixels.
        SM_CXICON=11,           // Default width of an icon, in pixels. The LoadIcon function can load only icons with the dimensions specified by SM_CXICON and SM_CYICON
        SM_CYICON=12,           // Default height of an icon, in pixels. The LoadIcon function can load only icons with the dimensions SM_CXICON and SM_CYICON.
        SM_CXCURSOR=13,         // Width of a cursor, in pixels. The system cannot create cursors of other sizes.
        SM_CYCURSOR=14,         // Height of a cursor, in pixels. The system cannot create cursors of other sizes.
        SM_CYMENU=15,           // Height of a single-line menu bar, in pixels.
        SM_CXFULLSCREEN=16,         // Width 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_CYFULLSCREEN=17,         // 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_CYKANJIWINDOW=18,        // 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_MOUSEWHEELPRESENT=75,    // Nonzero if a mouse with a wheel is installed; zero otherwise
        SM_CYHSCROLL=20,        // Height of the arrow bitmap on a vertical scroll bar, in pixels.
        SM_CXHSCROLL=21,        // Width of the arrow bitmap on a horizontal scroll bar, in pixels.
        SM_DEBUG=22,            // Nonzero if the debug version of User.exe is installed; zero otherwise.
        SM_SWAPBUTTON=23,           // Nonzero if the left and right mouse buttons are reversed; zero otherwise.
        SM_RESERVED1=24,        // Reserved for future use
        SM_RESERVED2=25,        // Reserved for future use
        SM_RESERVED3=26,        // Reserved for future use
        SM_RESERVED4=27,        // Reserved for future use
        SM_CXMIN=28,            // Minimum width of a window, in pixels.
        SM_CYMIN=29,            // Minimum height of a window, in pixels.
        SM_CXSIZE=30,           // Width of a button in a window's caption or title bar, in pixels.
        SM_CYSIZE=31,           // Height of a button in a window's caption or title bar, in pixels.
        SM_CXFRAME=32,          // 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.
        SM_CYFRAME=33,          // 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.
        SM_CXMINTRACK=34,           // Minimum tracking width of a window, in pixels. The user cannot drag the window frame to a size smaller than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message.
        SM_CYMINTRACK=35,           // Minimum tracking height of a window, in pixels. The user cannot drag the window frame to a size smaller than these dimensions. A window can override this value by processing the WM_GETMINMAXINFO message
        SM_CXDOUBLECLK=36,          // Width of the rectangle around the location of a first click in a double-click sequence, in pixels. The second click must occur within the rectangle defined by SM_CXDOUBLECLK and SM_CYDOUBLECLK for the system to consider the two clicks a double-click
        SM_CYDOUBLECLK=37,          // Height of the rectangle around the location of a first click in a double-click sequence, in pixels. The second click must occur within the rectangle defined by SM_CXDOUBLECLK and SM_CYDOUBLECLK for the system to consider the two clicks a double-click. (The two clicks must also occur within a specified time.)
        SM_CXICONSPACING=38,        // Width of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of size SM_CXICONSPACING by SM_CYICONSPACING when arranged. This value is always greater than or equal to SM_CXICON
        SM_CYICONSPACING=39,        // Height of a grid cell for items in large icon view, in pixels. Each item fits into a rectangle of size SM_CXICONSPACING by SM_CYICONSPACING when arranged. This value is always greater than or equal to SM_CYICON.
        SM_MENUDROPALIGNMENT=40,    // Nonzero if drop-down menus are right-aligned with the corresponding menu-bar item; zero if the menus are left-aligned.
        SM_PENWINDOWS=41,           // Nonzero if the Microsoft Windows for Pen computing extensions are installed; zero otherwise.
        SM_DBCSENABLED=42,          // Nonzero if User32.dll supports DBCS; zero otherwise. (WinMe/95/98): Unicode
        SM_CMOUSEBUTTONS=43,        // Number of buttons on mouse, or zero if no mouse is installed.
        SM_CXFIXEDFRAME=SM_CXDLGFRAME,  // Identical Values Changed After Windows NT 4.0  
        SM_CYFIXEDFRAME=SM_CYDLGFRAME,  // Identical Values Changed After Windows NT 4.0
        SM_CXSIZEFRAME=SM_CXFRAME,      // Identical Values Changed After Windows NT 4.0
        SM_CYSIZEFRAME=SM_CYFRAME,      // Identical Values Changed After Windows NT 4.0
        SM_SECURE=44,           // Nonzero if security is present; zero otherwise.
        SM_CXEDGE=45,           // Width of a 3-D border, in pixels. This is the 3-D counterpart of SM_CXBORDER
        SM_CYEDGE=46,           // Height of a 3-D border, in pixels. This is the 3-D counterpart of SM_CYBORDER
        SM_CXMINSPACING=47,         // Width of a grid cell for a minimized window, in pixels. Each minimized window fits into a rectangle this size when arranged. This value is always greater than or equal to SM_CXMINIMIZED.
        SM_CYMINSPACING=48,         // Height of a grid cell for a minimized window, in pixels. Each minimized window fits into a rectangle this size when arranged. This value is always greater than or equal to SM_CYMINIMIZED.
        SM_CXSMICON=49,         // Recommended width of a small icon, in pixels. Small icons typically appear in window captions and in small icon view
        SM_CYSMICON=50,         // Recommended height of a small icon, in pixels. Small icons typically appear in window captions and in small icon view.
        SM_CYSMCAPTION=51,          // Height of a small caption, in pixels
        SM_CXSMSIZE=52,         // Width of small caption buttons, in pixels.
        SM_CYSMSIZE=53,         // Height of small caption buttons, in pixels.
        SM_CXMENUSIZE=54,           // Width of menu bar buttons, such as the child window close button used in the multiple document interface, in pixels.
        SM_CYMENUSIZE=55,           // Height of menu bar buttons, such as the child window close button used in the multiple document interface, in pixels.
        SM_ARRANGE=56,          // Flags specifying how the system arranged minimized windows
        SM_CXMINIMIZED=57,          // Width of a minimized window, in pixels.
        SM_CYMINIMIZED=58,          // Height of a minimized window, in pixels.
        SM_CXMAXTRACK=59,           // Default maximum width 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 this value by processing the WM_GETMINMAXINFO message.
        SM_CYMAXTRACK=60,           // Default maximum height 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 this value by processing the WM_GETMINMAXINFO message.
        SM_CXMAXIMIZED=61,          // Default width, in pixels, of a maximized top-level window on the primary display monitor.
        SM_CYMAXIMIZED=62,          // Default height, in pixels, of a maximized top-level window on the primary display monitor.
        SM_NETWORK=63,          // Least significant bit is set if a network is present; otherwise, it is cleared. The other bits are reserved for future use
        SM_CLEANBOOT=67,        // Value that specifies how the system was started: 0-normal, 1-failsafe, 2-failsafe /w net
        SM_CXDRAG=68,           // Width of a rectangle centered on a drag point to allow for limited movement of the mouse pointer before a drag operation begins, in pixels.
        SM_CYDRAG=69,           // Height of a rectangle centered on a drag point to allow for limited movement of the mouse pointer before a drag operation begins. This value is in pixels. It allows the user to click and release the mouse button easily without unintentionally starting a drag operation.
        SM_SHOWSOUNDS=70,           // Nonzero if the user requires an application to present information visually in situations where it would otherwise present the information only in audible form; zero otherwise.
        SM_CXMENUCHECK=71,          // Width of the default menu check-mark bitmap, in pixels.
        SM_CYMENUCHECK=72,          // Height of the default menu check-mark bitmap, in pixels.
        SM_SLOWMACHINE=73,          // Nonzero if the computer has a low-end (slow) processor; zero otherwise
        SM_MIDEASTENABLED=74,       // Nonzero if the system is enabled for Hebrew and Arabic languages, zero if not.
        SM_MOUSEPRESENT=19,         // Nonzero if a mouse is installed; zero otherwise. This value is rarely zero, because of support for virtual mice and because some systems detect the presence of the port instead of the presence of a mouse.
        SM_XVIRTUALSCREEN=76,       // Windows 2000 (v5.0+) Coordinate of the top of the virtual screen
        SM_YVIRTUALSCREEN=77,       // Windows 2000 (v5.0+) Coordinate of the left of the virtual screen
        SM_CXVIRTUALSCREEN=78,      // Windows 2000 (v5.0+) Width of the virtual screen
        SM_CYVIRTUALSCREEN=79,      // Windows 2000 (v5.0+) Height of the virtual screen
        SM_CMONITORS=80,        // Number of display monitors on the desktop
        SM_SAMEDISPLAYFORMAT=81,    // Windows XP (v5.1+) Nonzero if all the display monitors have the same color format, zero 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.
        SM_IMMENABLED=82,           // Windows XP (v5.1+) Nonzero if Input Method Manager/Input Method Editor features are enabled; zero otherwise
        SM_CXFOCUSBORDER=83,        // Windows XP (v5.1+) Width of the left and right edges of the focus rectangle drawn by DrawFocusRect. This value is in pixels.
        SM_CYFOCUSBORDER=84,        // Windows XP (v5.1+) Height of the top and bottom edges of the focus rectangle drawn by DrawFocusRect. This value is in pixels.
        SM_TABLETPC=86,         // Nonzero if the current operating system is the Windows XP Tablet PC edition, zero if not.
        SM_MEDIACENTER=87,          // Nonzero if the current operating system is the Windows XP, Media Center Edition, zero if not.
        SM_CMETRICS_OTHER=76,       // Metrics Other
        SM_CMETRICS_2000=83,        // Metrics Windows 2000
        SM_CMETRICS_NT=88,          // Metrics Windows NT
        SM_REMOTESESSION=0x1000,    // Windows XP (v5.1+) 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 nonzero. If the calling process is associated with the Terminal Server console session, the return value is zero. The console session is not necessarily the physical console - see WTSGetActiveConsoleSessionId for more information.
        SM_SHUTTINGDOWN=0x2000,     // Windows XP (v5.1+) Nonzero if the current session is shutting down; zero otherwise
        SM_REMOTECONTROL=0x2001,    // Windows XP (v5.1+) This system metric is used in a Terminal Services environment. Its value is nonzero if the current session is remotely controlled; zero otherwise
    }

Parameters:

smIndex

System metric or configuration setting to retrieve. This parameter can be one of the following values. Note that all SM_CX* values are widths and all SM_CY* values are heights. Also note that all settings designed to return Boolean data represent TRUE as any nonzero value, and FALSE as a zero value.

Notes:

System metrics may vary from display to display.

GetSystemMetrics(SM_CMONITORS) counts only display monitors. This is different from EnumDisplayMonitors, which enumerates display monitors and also non-display pseudo-monitors.

The SM_ARRANGE setting specifies how the system arranges minimized windows, and consists of a starting position and a direction. The starting position can be one of the following values.

Value Meaning
ARW_BOTTOMLEFT Start at the lower-left corner of the screen (default position).
ARW_BOTTOMRIGHT Start at the lower-right corner of the screen. Equivalent to ARW_STARTRIGHT.
ARW_HIDE Hide minimized windows by moving them off the visible area of the screen.

ARW_TOPLEFT || Start at the upper-left corner of the screen. Equivalent to ARV_STARTTOP. ||

ARW_TOPRIGHT || Start at the upper-right corner of the screen. Equivalent to ARW_STARTTOP | SRW_STARTRIGHT. ||

The direction in which to arrange can be one of the following values.

Value Meaning
ARW_DOWN Arrange vertically, top to bottom.
ARW_LEFT Arrange horizontally, left to right.
ARW_RIGHT Arrange horizontally, right to left.
ARW_UP Arrange vertically, bottom to top.

Tips & Tricks:

Please add some!

Sample Code:

Please add some!

Alternative Managed API:

Do you know one? Please contribute it!

Information Supplied or Quoted from Microsoft Developer News (MSDN) 2006 Feb.

Documentation