Chapter 11. Windows APIs

The Windows API has a bad rap among many Access programmers who think it's too hard to figure out, too hard to call, or just plain mysterious. We're here to prove that none of these is the case?even if you've never seen the Windows API programmer's reference, you can use the Windows API, given some help. In this chapter, we'll present some interesting uses of the Windows API from within Access, with example forms and modules for each solution. In most cases, using these in your own applications entails little more than simply importing a module or two and then calling the functions. We've divided the solutions in this chapter into three broad categories, as follows:


The Windows user interface

You'll learn how to remove a form's system menu, how to maximize and minimize buttons at runtime, and how to draw attention to a specific form by flashing its titlebar or icon. We'll discuss language-independent classification of keypresses, so you can monitor exactly what keys have been pressed. We'll also show how to restrict mouse movement to a specific area on the screen.


The Windows shell

You'll learn how to have asynchronous code run another program and pause until the other program is done before continuing. We'll demonstrate a method for shutting down Windows under program control and show you all the options of the associated API functions. You'll learn to find and run an application, given an associated data file, and how to determine if the application is already running. You'll see how to retrieve a list of all open top-level windows (generally, one per application) and how to close a window from your VBA code.


Files, drives, and hardware

You'll learn how to set file date and time stamp information, which is useful if you're moving files around from within applications or making backups based on dates. You'll also learn how to retrieve information about your disk drives, hardware, and the current Windows environment as well as how to connect and disconnect from remote network devices programmatically or using standard dialogs.

Most of the solutions in this chapter instruct you to import one or more modules from the example databases. In each case, the module contains the Windows API user-defined types and function declarations you need for the example. If you've already imported a module with the specified name for a previous solution, you can skip it, since all modules with matching names contain the same code.