Online Book Reader

Home Category

Access Cookbook - Ken Getz [224]

By Root 2135 0
to the event procedure. Because this code could be used in multiple forms within the application, we chose to encapsulate it within each form's event procedure. You may wish to split the code into two parts: one part that maintains the static variables in the form's Timer event procedure, and a second common component that lives in a global module. To accomplish this, you'd have to pass three variables (by reference) to the common function: a form variable referencing the form, and the two static variables, sblnDirty and slngTimerStart.

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.

TIP

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.

11.1. Remove a Form's System Menu and Maximize/Minimize Buttons


Problem


Access makes it easy to remove the control box (often called the system menu) and the minimize and maximize buttons when you design forms, but there doesn't seem to be a way to do this at runtime. You have an application for which you'd like to be able to remove these buttons to control how users interact with the application. Is there a way to remove these items and then replace them later?

Solution


Removing or replacing these window controls requires changing the style bits for the particular window. Every window maintains a 32-bit value that describes its physical characteristics: for example, its border type and the existence of scrollbars, a system menu, and the minimize and maximize buttons. The values are stored as bit flags, in which the state of a single bit in the 32-bit value indicates the value of some characteristic of the window. In general, you can't change the state of many of these flags without recreating the window; by setting

Return Main Page Previous Page Next Page

®Online Book Reader