ACC: How to Determine the Current Screen Resolution (1.x/2.0)

Last reviewed: June 8, 1997
Article ID: Q113458
The information in this article applies to:
  • Microsoft Access versions 1.0, 1.1, 2.0

SUMMARY

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

This article describes a sample user-defined Access Basic function that you can use to determine the current screen resolution. This function is useful in determining if you are running in standard VGA mode (640 x 480) or Super VGA mode (800 x 600 or 1024 x 768).

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual in version 2.0.

MORE INFORMATION

The example below demonstrates how to create and use the sample GetScreenResolution() function.

Notes:

  • You may have some Microsoft Windows API functions defined in an existing Microsoft Access library; therefore, your declarations may be duplicates. If you receive a duplicate procedure name error message, remove or comment out the declarations statement in your code.
  • In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscores when re-creating this code in Access Basic.
  • In Microsoft Access version 2.0, you can create code in a form module. Code in a form module is restricted to that form. The Type statement used in this example must be global. You can use this code in a form's module if the Type statement is in the Declarations section of a global Access Basic module. For more information about the Type statement, search for "type" then "Type Statement" using the Microsoft Access Help menu.

  1. Create a new module, and type the following Declarations and function:

          '
          *****************************************************************
          ' DECLARATIONS SECTION
    

          Option Explicit
    

          Type RECT
    
              x1 As Integer
              y1 As Integer
              x2 As Integer
              y2 As Integer
          End Type
    
          Declare Function GetDesktopWindow Lib "User" () As Integer
          Declare Function GetWindowRect Lib "User" _
             (ByVal hWnd As Integer, rectangle As RECT) As Integer
    
          '
          *****************************************************************
          ' FUNCTION: GetScreenResolution()
          '
          ' PURPOSE:
          '   To determine the current screen size or resolution.
          '
          ' RETURN:
          '   The current screen resolution. Typically one of the following:
          '      640 x 480
          '      800 x 600
          '      1024 x 768
          '
          *****************************************************************
          Function GetScreenResolution () as String
              Dim R As RECT
              Dim hWnd As Integer
              Dim RetVal As Integer
              hWnd = GetDesktopWindow()
              RetVal = GetWindowRect(hWnd, R)
              GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
          End Function
    
    

  2. From the View menu, choose Immediate Window.

  3. Type the following line in the Immediate window, and then press ENTER:

          ? GetScreenResolution()
    

The current screen resolution will be displayed in the Immediate window. If the current resolution is standard VGA, the following will be displayed in the Immediate window:

   640x480

REFERENCES

For an example of how to determine the current screen resolution in Microsoft Access 95 and 97, please see the following article here in the Microsoft Knowledge Base:

   ARTICLE-ID: Q148395
   TITLE:      ACC: How to Determine the Current Screen Resolution (95/97)
 

	
	


Keywords : kbprg PgmApi
Version : 1.0 1.1 2.0
Platform : WINDOWS
Hardware : X86
Issue type : kbhowto


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 8, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.