Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

ACC2000: How to Determine the Current Screen Resolution


View products that this article applies to.

Summary

This article shows you how to create a sample user-defined Visual Basic for Applications function to determine the current screen resolution. You can use this function to determine if you are running in standard VGA mode (640 x 480) or Super VGA mode (800 x 600, 1024 x 768 or 1600 x 1200).

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.

↑ Back to the top


More information

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

NOTE: 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.

  1. Create a new module, and type the following Declarations and function:
    '*****************************************************************
    ' DECLARATIONS SECTION
    '*****************************************************************
    
    Option Explicit
    
    Type RECT
       x1 As Long
       y1 As Long
       x2 As Long
       y2 As Long
    End Type
    
    ' NOTE: The following declare statements are case sensitive.
    
    
    Declare Function GetDesktopWindow Lib "User32" () As Long
    Declare Function GetWindowRect Lib "User32" _
          (ByVal hWnd As Long, rectangle As RECT) As Long
    
    '*****************************************************************
    ' 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 Long
       Dim RetVal As Long
    
       hWnd = GetDesktopWindow()
       RetVal = GetWindowRect(hWnd, R)
       GetScreenResolution = (R.x2 - R.x1) & "x" & (R.y2 - R.y1)
    
    End Function
    					
  2. On the View menu, click Immediate Window.
  3. Type the following line in the Immediate Window, and then press ENTER:
    ? GetScreenResolution()
    						


    Note that the current screen resolution is displayed in the Immediate window. If the current resolution is standard VGA, the following is displayed in the Immediate window:
    640x480

↑ Back to the top


References

For additional information about API Calls, please see the following article in the Microsoft Knowledge Base:
210115 How to Convert API Calls from 16-bit to 32-bit

↑ Back to the top


Keywords: KB210106, kbprogramming, kbhowto, kbdisplay

↑ Back to the top

Article Info
Article ID : 210106
Revision : 6
Created on : 10/11/2006
Published on : 10/11/2006
Exists online : False
Views : 412