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:
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.
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.
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.