ACC: How to Retrieve the MS Access Window Handle (1.x/2.0)ID: Q113881
|
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:
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.
Option Explicit
Declare Function GetActiveWindow Lib "User" () As Integer
Declare Function GetParent Lib "User" (ByVal hWnd As Integer) _
As Integer
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
Declare Function ShowWindow% Lib "User" (ByVal hWnd%, _
ByVal nCmdShow%)
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
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
Declare Function IsIconic Lib "User" (ByVal hWnd As Integer) _
As Integer
Declare Function IsZoomed Lib "User" (ByVal hWnd As Integer) _
As Integer
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
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)
Function AccessMoveSize (iX As Integer, iY As Integer, _
iWidth As Integer, iHeight As Integer)
MoveWindow GetAccesshWnd(), iX, iY, iWidth, iHeight, True
End Function
For more information about Window handles in Microsoft Access version 7.0,
please see the following article here in the Microsoft Knowledge Base.
Q147214 ACC95: How to Retrieve and Use the MS Access Window
Handle
Additional query words: hWnd hWindow hWin
Keywords : kbprg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: April 2, 1999