ACC: How to Use the GetSystemMetrics() API Call (88922)



The information in this article applies to:

  • Microsoft Access 1.0
  • Microsoft Access 1.1
  • Microsoft Access 2.0
  • Microsoft Access for Windows 95 7.0
  • Microsoft Access 97

This article was previously published under Q88922

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

In the Windows environment, various display resolutions may cause screens to appear out of proportion. As a developer, you can get the width and height of various elements of the window display by using the Windows application programming interface (API) function GetSystemMetrics(). Incorporating this function into a Microsoft Access application gives you more information for designing the user interface. This article describes the GetSystemMetrics() API function and shows you how to call the function from Microsoft Access.

This article assumes that you are familiar with Visual Basic for Applications and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information about Visual Basic for Applications, please refer to your version of the "Building Applications with Microsoft Access" manual.

NOTE: Visual Basic for Applications is called Access Basic in Microsoft Access versions 1.x and 2.0. For more information about Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x or the "Building Applications" manual in Microsoft Access version 2.0.

MORE INFORMATION

The Windows GetSystemMetrics() API function retrieves information about the system metrics (the width and height of various display elements of a particular window). The GetSystemMetrics() function can also return flags that indicate whether a mouse is present or if the meaning of the left and right mouse buttons have been reversed. System metrics are dependent upon the system display and may vary from display to display.

To use the GetSystemMetrics() functions, follow these steps:
  1. Place one the following Declare statements in the Declarations section of a module, depending on which version of Microsoft Access you are using.

    In Microsoft Access 7.0 and 97:
          Declare Function GetSystemMetrics& Lib "User32" (ByVal nIndex&)
    
          NOTE: The above statement is case-sensitive.
    
       In Microsoft Access 1.x or 2.0:
    
          Declare Function GetSystemMetrics% Lib "user" (ByVal nIndex%)
    						
  2. Depending on which window property you want to determine, you must define the correct constant to pass to the GetSystemMetrics() function. Below are sample declarations of the constants and their meaning. Constants by default are Private. If you want to place these constants in a global module and have them available for the entire application, then you would have to add Public at the beginning of the constant statement. (Public Const SM_CXSCREEN = 0). For a complete list of the constants available for Windows 95, please refer to the Win32 Software Development Kit.
         Const SM_CXSCREEN = 0        ' Width of screen
         Const SM_CYSCREEN = 1        ' Height of screen
         Const SM_CXFULLSCREEN = 16   ' Width of window client area
         Const SM_CYFULLSCREEN = 17   ' Height of window client area
         Const SM_CYMENU = 15         ' Height of menu
         Const SM_CYCAPTION = 4       ' Height of caption or title
         Const SM_CXFRAME = 32        ' Width of window frame
         Const SM_CYFRAME = 33        ' Height of window frame
         Const SM_CXHSCROLL = 21      ' Width of arrow bitmap on
                                      '  horizontal scroll bar
         Const SM_CYHSCROLL = 3       ' Height of arrow bitmap on
                                      '  horizontal scroll bar
         Const SM_CXVSCROLL = 2       ' Width of arrow bitmap on
                                      '  vertical scroll bar
         Const SM_CYVSCROLL = 20      ' Height of arrow bitmap on
                                      '  vertical scroll bar
         Const SM_CXSIZE = 30         ' Width of bitmaps in title bar
         Const SM_CYSIZE = 31         ' Height of bitmaps in title bar
         Const SM_CXCURSOR = 13       ' Width of cursor
         Const SM_CYCURSOR = 14       ' Height of cursor
         Const SM_CXBORDER = 5        ' Width of window frame that cannot
                                      '  be sized
         Const SM_CYBORDER = 6        ' Height of window frame that cannot
                                      '  be sized
         Const SM_CXDOUBLECLICK = 36  ' Width of rectangle around the
                                      '  location of the first click. The
                                      '  second click must occur in the
                                      '  same rectangular location.
         Const SM_CYDOUBLECLICK = 37  ' Height of rectangle around the
                                      '  location of the first click. The
                                      '  second click must occur in the
                                      '  same rectangular location.
         Const SM_CXDLGFRAME = 7      ' Width of dialog frame window
         Const SM_CYDLGFRAME = 8      ' Height of dialog frame window
         Const SM_CXICON = 11         ' Width of icon
         Const SM_CYICON = 12         ' Height of icon
         Const SM_CXICONSPACING = 38  ' Width of rectangles the system
                                      ' uses to position tiled icons
         Const SM_CYICONSPACING = 39  ' Height of rectangles the system
                                      ' uses to position tiled icons
         Const SM_CXMIN = 28          ' Minimum width of window
         Const SM_CYMIN = 29          ' Minimum height of window
         Const SM_CXMINTRACK = 34     ' Minimum tracking width of window
         Const SM_CYMINTRACK = 35     ' Minimum tracking height of window
         Const SM_CXHTHUMB = 10       ' Width of scroll box (thumb) on
                                      '  horizontal scroll bar
         Const SM_CYVTHUMB = 9        ' Width of scroll box (thumb) on
                                      '  vertical scroll bar
         Const SM_DBCSENABLED = 42    ' Returns a non-zero if the current
                                      '  Windows version uses double-byte
                                      '  characters, otherwise returns
                                      '  zero
         Const SM_DEBUG = 22          ' Returns non-zero if the Windows
                                      '  version is a debugging version
         Const SM_MENUDROPALIGNMENT = 40
                                      ' Alignment of pop-up menus. If zero,
                                      '  left side is aligned with
                                      '  corresponding left side of menu-
                                      '  bar item. If non-zero, left side
                                      '  is aligned with right side of
                                      '  corresponding menu bar item
         Const SM_MOUSEPRESENT = 19   ' Non-zero if mouse hardware is
                                      '  installed
         Const SM_PENWINDOWS = 41     ' Handle of Pen Windows dynamic link
                                      '  library if Pen Windows is
                                      '  installed
         Const SM_SWAPBUTTON = 23     ' Non-zero if the left and right
                                      ' mouse buttons are swapped
The following sample call will return the height of a form's caption bar:
   HeightY% = GetSystemMetrics(SM_CYCAPTION)
				

REFERENCES

For more information about constants, search for "Const," and then "Const Statement" using the Microsoft Access Help Index.

For more information about Declare, search for "Declare," and then "Declare Statement," using the Microsoft Access Help Index.

Modification Type:MinorLast Reviewed:10/11/2006
Keywords:kbhowto kbProgramming kbusage KB88922