Help and Support
 

powered byLive Search

ACC: How to Retrieve the MS Access Window Handle (1.x/2.0)

Retired KB ArticleThis article was written about products for which Microsoft no longer offers support. Therefore, this article is offered "as is" and will no longer be updated.
Article ID:113881
Last Review:May 6, 2003
Revision:2.0
This article was previously published under Q113881
On This Page

SUMMARY

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

This article describes a sample user-defined Access Basic function that you can use to get the handle to the Microsoft Access window. This article also describes how to use the sample function to:
Minimize, maximize, and restore the Microsoft Access window
Determine if the Microsoft Access window is minimized, maximized or restored
Move and size the Microsoft Access window
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.

Back to the top

MORE INFORMATION

Every window in the Microsoft Windows environment has a unique number, or window handle, assigned to it that is used to identify the window. The window handle is a required argument for many Microsoft Windows application programming interface (API) functions.

The following steps describe how to create the sample function GetAccesshWnd() that you can use to get the Microsoft Access window handle:

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.

NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore when re-creating this code in Access Basic.
1.Create a new module.
2.Add the following lines to the module's Declarations section:
      Option Explicit

      Declare Function GetActiveWindow Lib "User" () As Integer
      Declare Function GetParent Lib "User" (ByVal hWnd As Integer) _
         As Integer
						
3.Enter the following function in the module:
      Function GetAccesshWnd ()
         Dim hWnd As Integer
         Dim hWndAccess As Integer

         ' Get the handle to the currently active window.
         hWnd = GetActiveWindow()
         hWndAccess = hWnd

         ' Find the top window without a parent window.
         While hWnd <> 0
            hWndAccess = hWnd
            hWnd = GetParent(hWnd)
         Wend

         GetAccesshWnd = hWndAccess

      End Function
						

Back to the top

How to Use the GetAccesshWnd() Function

General Use:
1.Choose Immediate Window from the View menu in the module's Design view.
2.Type the following and then press ENTER:

? GetAccesshWnd()

The window handle for the Immediate window will be returned.
How to Minimize, Maximize, or Restore the Microsoft Access Window:
1.Add the following to the module's Declarations section:
      Declare Function ShowWindow% Lib "User" (ByVal hWnd%, _
         ByVal nCmdShow%)

      Global Const SW_MAXIMIZE = 3
      Global Const SW_SHOWNORMAL = 1
      Global Const SW_SHOWMINIMIZED = 2
						
2.Enter the following functions in the module:
      Function AccessMinimize()
         AccessMinimize = ShowWindow(GetAccesshWnd(), SW_SHOWMINIMIZED)
      End Function

      Function AccessMaximize()
         AccessMaximize = ShowWindow(GetAccesshWnd(), SW_MAXIMIZE)
      End Function

      Function AccessRestore()
         AccessRestore = ShowWindow(GetAccesshWnd(), SW_SHOWNORMAL)
      End Function
						
3.To run these functions, type ? <function name>() in the module's Immediate window.
How to Determine If the Microsoft Access Window Is Minimized, Maximized, or Restored:
1.Add the following to the module's Declarations section:
      Declare Function IsIconic Lib "User" (ByVal hWnd As Integer) _
         As Integer
      Declare Function IsZoomed Lib "User" (ByVal hWnd As Integer) _
         As Integer
						
2.Enter the following functions in the module:
      Function IsAccessMaximized ()
         If IsZoomed(GetAccesshWnd()) = 0 Then
            IsAccessMaximized = False
         Else
            IsAccessMaximized = True
         End If
      End Function

      Function IsAccessMinimized ()
         If IsIconic(GetAccesshWnd()) = 0 Then
            IsAccessMinimized = False
         Else
            IsAccessMinimized = True
         End If
      End Function

      Function IsAccessRestored ()
         If IsAccessMaximized() = False And _
               IsAccessMinimized() = False Then
            IsAccessRestored = True
         Else
            IsAccessRestored = False
         End If
      End Function
						
3.To run these functions, type ? <function name>() in the module's Immediate window. For example, type

? IsAccessMaximized()

to return a -1 if the Microsoft Access window is maximized, or a 0 if it is not.
How to Move and Size the Microsoft Access Window:
1.Add the following to the module's Declarations section:
      Declare Sub MoveWindow Lib "User" (ByVal hWnd As Integer, _
         ByVal X As Integer, ByVal Y As Integer, _
         ByVal nWidth As Integer, ByVal nHeight As Integer, _
         ByVal bRepaint As Integer)
						
2.Enter the following function in the module:
      Function AccessMoveSize (iX As Integer, iY As Integer, _
         iWidth As Integer, iHeight As Integer)
         MoveWindow GetAccesshWnd(), iX, iY, iWidth, iHeight, True
      End Function
						
To move the Microsoft Access window to the upper left corner of the screen and size it to the standard VGA display size of 640 x 480 pixels, type the following in the module's Immediate window:

? AccessMoveSize(0, 0, 640, 480)

On a computer configured with the standard VGA video driver, this will give the Microsoft Access window the appearance of being maximized, although it is really restored and sized to fill the screen. Note that the dimensions you supply to this function are in pixels.

Back to the top

REFERENCES

For more information about Window handles in Microsoft Access version 7.0, please see the following article here in the Microsoft Knowledge Base.

147214 (http://support.microsoft.com/kb/147214/EN-US/) ACC95: How to Retrieve and Use the MS Access Window Handle

Back to the top


APPLIES TO
Microsoft Access 1.0 Standard Edition
Microsoft Access 1.1 Standard Edition
Microsoft Access 2.0 Standard Edition

Back to the top

Keywords: 
kbhowto kbprogramming KB113881

Back to the top

Article Translations

 

Other Support Options

  • Need More Help?
    Contact a Support professional by E-mail, Online or Phone.
  • Customer Service
    For non-technical assistance with product purchases, subscriptions, online services, events, training courses, corporate sales, piracy issues, and more.
  • Newsgroups
    Pose a question to other users. Discussion groups and Forums about specific Microsoft products, technologies, and services.