How to Invoke GetSystemMetrics Windows API Function from VB

ID: Q77061


The information in this article applies to:


SUMMARY

The Windows API GetSystemMetrics function can return useful information about the Windows system. GetSystemMetrics can be called directly from Visual Basic for Windows or from the Control Development Kit (CDK) to get system metrics for a particular display adapter, retrieve information about the Windows debug mode, or retrieve information about a mouse configuration.

The Visual Basic for Windows CDK is shipped as part of the Professional Edition of Microsoft Visual Basic versions 2.0 and 3.0 for Windows.


MORE INFORMATION

The Windows GetSystemMetrics function call retrieves information about the system metrics. The system metrics are the widths and heights of various display elements of the particular window display. The GetSystemMetrics function can also return flags that indicate whether the current Windows version is a debugging version, whether a mouse is present, or whether the meaning of the left and right mouse button has been changed. System metrics depend on the system display, and may vary from display to display.

The Visual Basic for Windows declaration for GetSystemMetrics is:


   Declare Function GetSystemMetrics% Lib "user" (ByVal nIndex%) 

The value nIndex% specifies the system measurement to be retrieved. All measurements are in pixels.

The value returned from the GetSystemMetrics% function specifies the system metrics.

Below is a sample call to determine if the present version of Windows is a debugging version:

   ScaleMode = 3  ' Select pixel.
   Print "Debugging version : "; GetSystemMetrics(SM_DEBUG) 

The constants and meaning for nIndex% are as follows:

  Constant Name(Value)..Description
  ---------------------------------
  SM_CXSCREEN(0)........Width of screen
  SM_CYSCREEN(1)........Height of screen
  SM_CXFRAME(32)........Width of window frame that can be sized
  SM_CYFRAME(33)........Height of window frame that can be sized
  SM_CXVSCROLL(2).......Width of arrow bitmap on vertical scroll bar
  SM_CYVSCROL(20).......Height of arrow bitmap on vertical scroll bar
  SM_CXHSCROLL(21)......Width of arrow bitmap on horizontal scroll bar
  SM_CYHSCROLL(3).......Height of arrow bitmap on horizontal scroll bar
  SM_CYCAPTION(4).......Height of caption
  SM_CXBORDER(5)........Width of window frame that cannot be sized
  SM_CYBORDER(6)........Height of window frame that cannot be sized
  SM_CXDLGFRAME(7)......Width of frame when window has WS_DLGFRAME style
  SM_CYDLGFRAME(8)......Height of frame when window has WS_DLGFRAME style
  SM_CXHTHUMB(10).......Width of thumb on horizontal scroll bar
  SM_CYHTHUMB(9)........Height of thumb on horizontal scroll bar
  SM_CXICON(11).........Width of icon
  SM_CYICON(12).........Height of icon
  SM_CXCURSOR(13).......Width of cursor
  SM_CYCURSOR(14).......Height of cursor
  SM_CYMENU(15).........Height of single-line menu
  SM_CXFULLSCREEN(16)...Width of window client area for full-screen window
  SM_CYFULLSCREEN(17)...Height of window client area for full-screen
                        window (height - caption)
  SM_CYKANJIWINDOW(18)..Height of Kanji window
  SM_CXMINTRACK(34).....Minimum tracking width of window
  SM_CYMINTRACK(35).....Minimum tracking height of window
  SM_CXMIN(28)..........Minimum width of window
  SM_CYMIN(29)..........Minimum width of window
  SM_CXSIZE(30).........Width of bitmaps contained in the title bar
  SM_CYSIZE(31).........Height of bitmaps contained in the title bar
  SM_MOUSEPRESENT(19)...Mouse present
  SM_DEBUG(22)..........Nonzero if Windows debug version 

Additional query words: 2.00 3.00


Keywords          : 
Version           : 
Platform          : 
Issue type        : 

Last Reviewed: June 11, 1999