You are currently offline, waiting for your internet to reconnect

ACC2000: How to Use the GetSystemMetrics() API Call

This article was previously published under Q210603
This article has been archived. It is offered "as is" and will no longer be updated.
Advanced: Requires expert coding, interoperability, and multiuser skills.

This article applies to a Microsoft Access database (.mdb) and to a Microsoft Access project (.adp).

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

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements.
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. Create a new Access database.
  2. Create a new module.
  3. Place the following Declare statement in the Declarations section of a module:
    Declare Function GetSystemMetrics& Lib "User32" (ByVal nIndex&)   						
    NOTE: This Declare statement is case-sensitive.
  4. Depending on which window property you want to determine, you must define the correct constant to pass to the GetSystemMetrics() function. Following 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 so that they are available to the entire application, add Public to the beginning of the constant statement (Public Const SM_CXSCREEN = 0). For a complete list of the constants available for Windows 95 and 98, please refer to the Win32 Software Development Kit.

    Starting on the next line after the Declare statement, type the following functions in the Declarations section:
    Const SM_CXSCREEN = 0        ' Width of screenConst SM_CYSCREEN = 1        ' Height of screenConst SM_CXFULLSCREEN = 16   ' Width of window client areaConst SM_CYFULLSCREEN = 17   ' Height of window client areaConst SM_CYMENU = 15         ' Height of menuConst SM_CYCAPTION = 4       ' Height of caption or titleConst SM_CXFRAME = 32        ' Width of window frameConst SM_CYFRAME = 33        ' Height of window frameConst SM_CXHSCROLL = 21      ' Width of arrow bitmap on                             '  horizontal scroll barConst SM_CYHSCROLL = 3       ' Height of arrow bitmap on                             '  horizontal scroll barConst SM_CXVSCROLL = 2       ' Width of arrow bitmap on                             '  vertical scroll barConst SM_CYVSCROLL = 20      ' Height of arrow bitmap on                             '  vertical scroll barConst SM_CXSIZE = 30         ' Width of bitmaps in title barConst SM_CYSIZE = 31         ' Height of bitmaps in title barConst SM_CXCURSOR = 13       ' Width of cursorConst SM_CYCURSOR = 14       ' Height of cursorConst SM_CXBORDER = 5        ' Width of window frame that cannot                             '  be sizedConst SM_CYBORDER = 6        ' Height of window frame that cannot                             '  be sizedConst 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 windowConst SM_CYDLGFRAME = 8      ' Height of dialog frame windowConst SM_CXICON = 11         ' Width of iconConst SM_CYICON = 12         ' Height of iconConst SM_CXICONSPACING = 38  ' Width of rectangles the system                             ' uses to position tiled iconsConst SM_CYICONSPACING = 39  ' Height of rectangles the system                             ' uses to position tiled iconsConst SM_CXMIN = 28          ' Minimum width of windowConst SM_CYMIN = 29          ' Minimum height of windowConst SM_CXMINTRACK = 34     ' Minimum tracking width of windowConst SM_CYMINTRACK = 35     ' Minimum tracking height of windowConst SM_CXHTHUMB = 10       ' Width of scroll box (thumb) on                             '  horizontal scroll barConst SM_CYVTHUMB = 9        ' Width of scroll box (thumb) on                             '  vertical scroll barConst SM_DBCSENABLED = 42    ' Returns a non-zero if the current                             '  Windows version uses double-byte                             '  characters, otherwise returns                             '  zeroConst SM_DEBUG = 22          ' Returns non-zero if the Windows                             '  version is a debugging versionConst 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 itemConst SM_MOUSEPRESENT = 19   ' Non-zero if mouse hardware is                             '  installedConst SM_PENWINDOWS = 41     ' Handle of Pen Windows dynamic link                             '  library if Pen Windows is                             '  installedConst SM_SWAPBUTTON = 23     ' Non-zero if the left and right                             ' mouse buttons are swapped					
  5. Save the new module as MetricsCode.
  6. Create a new blank form with the following properties:
       Form: Test1   -------------------------   Caption: TestForm   ControlSource: &none>   Command button   ---------------------------   Name: Button0   Caption: My Button					
  7. Set the OnClick property of the Button0 command button to the following event procedure:
    'The following call returns the height of the form's caption barPrivate Sub Command0_Click()  Dim HeightY As String  HeightY = GetSystemMetrics(SM_CYCAPTION)  MsgBox HeightYEnd Sub					
  8. View the form in Form view and click the command button. Note that you see the height of the form's caption bar in a message box.
REFERENCES
For more information about declaring functions, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Declare Statement in the Office Assistant or the Answer Wizard, and then click Search to view the topic.

For more information about constants, in the Visual Basic Editor, click Microsoft Visual Basic Help on the Help menu, type Const Statement in the Office Assistant or the Answer Wizard, and then click Search to view the topic.
inf
Properties

Article ID: 210603 - Last Review: 12/05/2015 11:35:29 - Revision: 3.2

  • Microsoft Access 2000 Standard Edition
  • kbnosurvey kbarchive kbhowto kbprogramming KB210603
Feedback