ðH geocities.com /Heartland/Pond/4805/API8.htm geocities.com/Heartland/Pond/4805/API8.htm .delayed x ¹PÔJ ÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÈ Ð®ì Ø OK text/html p0i Ø ÿÿÿÿ b‰.H Sun, 20 Jan 2002 12:59:36 GMT ; Mozilla/4.5 (compatible; HTTrack 3.0x; Windows 98) en, * ¹PÔJ Ø
ACC2000: How to Retrieve the Microsoft Access Window Handle |
The
information in this article applies to:
Advanced: Requires expert coding,
interoperability, and multiuser skills.
This article applies to a Microsoft Access database (.mdb) and a Microsoft
Access project (.adp).
This article shows you how to create a sample
user-defined function to retrieve the handle to the Microsoft Access window. It
also shows you how to create functions to determine and change the Microsoft
Access window state (maximized, minimized, restored) as well as its size and
position.
Microsoft provides programming examples for illustration
only, without warranty either expressed or implied, including, but not limited
to, the implied warranties of merchantability and/or fitness for a particular
purpose. This article assumes that you are familiar with the programming
language being demonstrated and the tools used to create and debug procedures.
Microsoft support professionals 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 needs. If you have
limited programming experience, you may want to contact a Microsoft Certified
Partner or the Microsoft fee-based consulting line at (800) 936-5200. For more
information about Microsoft Certified Partners, please see the following page
on the World Wide Web:
http://www.microsoft.com/partner/referral/
For
more information about the support options available from Microsoft, please see
the following page on the World Wide Web:
http://support.microsoft.com/directory/overview.asp
Every
window in the Microsoft Windows environment has a unique number, or window
handle, assigned to it. The window handle identifies the window and is a
required argument for many Microsoft Windows application programming interface
(API) functions.
To
create the sample function GetAccesshWnd() that you can use to retrieve the
Microsoft Access window handle, follow these steps:
NOTE: You may have some Microsoft Windows API functions defined in an
existing Microsoft Access library, in which case your declarations may be
duplicates. If you receive a duplicate procedure name error message, remove or
comment out the declarations statement in your code.
Option Explicit
Declare Function apiGetActiveWindow Lib "user32" Alias "GetActiveWindow" () As Long
Declare Function apiGetParent Lib "user32" Alias "GetParent" (ByVal hwnd As Long) As Long
Function GetAccesshWnd ()
Dim hWnd As Long
Dim hWndAccess As Long
' Get the handle to the currently active window.
hWnd = apiGetActiveWindow()
hWndAccess = hWnd
' Find the top window (which has no parent window).
While hWnd <> 0
hWndAccess = hWnd
hWnd = apiGetParent(hWnd)
Wend
GetAccesshWnd = hWndAccess
End Function
To test the
GetAccesshWnd() function, follow these steps:
Declare Function apiShowWindow Lib "user32" Alias "ShowWindow"
(ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
Global Const SW_MAXIMIZE = 3
Global Const SW_SHOWNORMAL = 1
Global Const SW_SHOWMINIMIZED = 2
Function AccessMinimize()
AccessMinimize = apiShowWindow(GetAccesshWnd(), SW_SHOWMINIMIZED)
End Function
Function AccessMaximize()
AccessMaximize = apiShowWindow(GetAccesshWnd(), SW_MAXIMIZE)
End Function
Function AccessRestore()
AccessRestore = apiShowWindow(GetAccesshWnd(), SW_SHOWNORMAL)
End Function
2. Declare Function apiIsIconic Lib "user32" Alias "IsIconic" (ByVal hwnd As Long) As Long
Declare Function apiIsZoomed Lib "user32" Alias "IsZoomed" (ByVal hwnd As Long) As Long
Function IsAccessMaximized ()
If apiIsZoomed(GetAccesshWnd()) = 0 Then
IsAccessMaximized = False
Else
IsAccessMaximized = True
End If
End Function
Function IsAccessMinimized ()
If apiIsIconic(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 Function apiMoveWindow Lib "user32" Alias "MoveWindow" _
(ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal _
nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) _
As Long
Function AccessMoveSize (iX As Integer, iY As Integer, iWidth As _
Integer, iHeight As Integer)
apiMoveWindow 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 ? AccessMoveSize(0, 0,
640, 480) in the module's Immediate window, and then press ENTER.
On a computer configured with the standard VGA video driver, this gives the
Microsoft Access window the appearance of being maximized, although it is
really restored and sized to fill the screen. Note that the dimensions that you
supply to this function are in pixels.
For more information
about window handles, in the Visual Basic Editor, click Microsoft Visual
Basic Help on the Help menu, type hwnd property in the Office
Assistant or the Answer Wizard, and then click Search to view the topic.