ACC: Using SetSysModalWindow() API Call in Access Basic
ID: Q88171
|
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.
In Microsoft Access Basic, you can make an application modal so that users
cannot switch to other Windows-based programs while the Microsoft Access
application is active. This functionality is achieved with the following
Windows application program interface (API) functions:
SetSysModalWindow()
-and-
FindWindow()
This article discusses the use of the SetSysModalWindow() API function and
provides an example of its use in Access Basic.
NOTE: The SetSysModalWindow() API function is not supported under Win32. As
a result, you cannot use this function with Microsoft Access for Windows 95
version 7.0.
MORE INFORMATION
Microsoft Windows is designed so that the user can switch between
applications without terminating one program to run another. There may be
times, however, when a Microsoft Access application needs to restrict the
user from switching to another application. Examples of this are a security
system or time-critical application that needs to run uninterruptedly.
SetSysModalWindow() Function Usage Notes
Consider all of the following usage notes before making a window
system-modal:
- If an application passes the handle of the window as an argument
to the SetSysModalWindow() function, the user is limited to that
window. This prevents the user from moving to other applications or
bringing up the Task List (either with the mouse or by pressing
CTRL+ESC).
- If an application uses the SetSysModalWindow function in
conjunction with the GetSystemMenu() function, the Control (system)
menu is disabled and the user is prevented from quitting Windows
by pressing ALT+F4.
- A window that is system-modal cannot be minimized, maximized, moved,
or sized. Microsoft Access Help is created with a separate Windows
Help file; therefore, help windows created with the Windows Help
Compiler are not available to the user.
- When an application uses the SetSysModalWindow() API function, the
system-modal window must be closed before other applications or
windows can be accessed. Therefore, when using this function, be
sure that the application has a means to exit Microsoft Access.
- Any child window that is created by a system-modal window becomes
a system-modal window. For example, if Microsoft Access is system-
modal and a form is opened, that form becomes system-modal until
it is closed.
How to Use the SetSysModalWindow() Function
To use the SetSysModalWindow() API function within Access Basic, create the
sample code below.
NOTE: In this sample code, an underscore (_) is used as a line continuation
character. Remove the underscore from the end of the line when re-creating
this code in Access Basic.
- Type the following lines in the Declarations section:
Option Explicit
Declare Function SetSysModalWindow% Lib "User" ( _
ByVal hwnd%)
Declare Function FindWindow% Lib "User" (_
ByVal lpszClassName As Any, _
ByVal lpszWindow As Any)
- Type the following procedure:
Function System_Modal_Test ()
Const lpClassName = "OMain"
' Declares the class name constant used in
' the FindWindow() API function.
Dim AccessHandle
Dim Success As Integer
' The FindWindow() functions returns the handle for Microsoft
' Access.
AccessHandle = FindWindow(lpClassName, 0&) 'Note this is a zero
' The handle for Microsoft Access is sent; then, Microsoft Access
' becomes modal.
Success = SetSysModalWindow(AccessHandle)
End Function
- Save the module as Modal Access, and then choose the OK button.
- From the Run menu, choose Compile All.
- Type the following line in the Immediate window, and then press ENTER:
?System_Modal_Test()
After running the program, test the modal functionality by trying to select
other windows or resize or move the system-modal window.
REFERENCES
For more information about the Modal property, search for "Modal," and then
"Modal Property" using the Microsoft Access Help menu.
For more information about API functions, refer to:
- "Microsoft Windows Software Development Kit," Microsoft Press, 1992
- "Programming Windows: The Microsoft Guide to Writing Applications
for Windows 3," Charles Petzold, Microsoft Press, 1990
- "Programmer's Reference Library: Microsoft Windows 3.1 Guide to
Programming Reference," Volumes 1-6, Microsoft Press, 1992
Keywords : kbprg
Version : 1.0 1.1 2.0
Platform : WINDOWS
Issue type : kbhowto
Last Reviewed: March 9, 1999