Online Book Reader

Home Category

Access Cookbook - Ken Getz [225]

By Root 2146 0
or clearing the bits in the window's style value, however, you can force the system menu and the minimize/maximize buttons to appear or disappear.

Load and run frmSystemItems from 11-01.MDB. This form, shown in Figure 11-1, allows you to add or remove the control menu, the minimize button, and the maximize button from the current form. Select items on the form to make the corresponding items visible, or deselect to remove them. Once you've made your choices, click on the Execute button, and the code will remove or replace the items you've chosen.

Figure 11-1. frmSystemItems allows you to remove or replace any of the system items

To include this functionality in your own applications, follow these steps:

Import the module basControl from 11-01.MDB.

To remove or replace a form's system items, call the acbFormSystemItems subroutine, passing to it the four parameters shown in Table 11-1.

For example, the following statement, called from a button's Click event in a form's module, will show the system menu but will hide the minimize and maximize buttons:

acbFormSystemItems Me, True, False, False

Though Access does provide the ControlBox, MaxButton, and MinButton properties for forms, they're read-only once the form is in use; if you need to alter these properties at runtime, you'll need to use acbFormSystemItems instead of changing the properties directly.

Table 11-1. Parameters for acbFormSystemItems

Parameter

Type

Value

frm

Form

Reference to the current form

blnShowSystemMenu

Integer

True = Show system menu; False = Hide

blnShowMaxButton

Integer

True = Show maximize button; False = Hide

blnShowMinButton

Integer

True = Show minimize button; False = Hide

OLD VERSUS NEW USE OF WINDOW BUTTONS

The behavior of the control box and minimize and maximize buttons has changed. If you're running Windows 95 or later, using acbFormSystemItems to remove one of the minimize or maximize buttons leaves them both visible but disables the one you've requested to hide. Removing them both with acbFormSystemItems makes them both invisible. Under Windows NT and earlier, these buttons are independent, and using the subroutine to remove one makes it invisible. Under Windows 95 or later, removing the control box also removes the minimize and maximize buttons. Under Windows NT or earlier, these items are independent.

Discussion


The bulk of the work in controlling these system items takes place in the private HandleStyles function in the basControl module. This function accepts a window handle (the hWnd property of a form) and three True/False values indicating which options you want to see and which you want removed. Like every window, the window you want to alter maintains a 32-bit value, its style value. Within that long integer, each of the 32 positions represents one of the possible styles for the window. If the bit is 1, the style is set on; if it's 0, the style is set off. HandleStyles builds up two long integers, each containing a series of 32 bits. The first, lngStylesOn, contains all 0s, except for the bits representing the styles you want turned on, which contain 1s. The other, lngStylesOff, contains all 1s, except for the bits representing the styles you want turned off, which contain 0s.

Using the AND operator to combine the current window style with lngStylesOff sets each style whose bit contains 0 in lngStylesOff to be 0. Using the OR operator to combine the current window style with lngStylesOn sets each style whose bit contains 1 in lngStylesOn to be 1. For example, suppose the current window style value is this:

10001000 10001010 10101011 01101101

The value in lngStylesOff contains 1s in all positions except the ones you want turned off, which contain 0s. If the value of lngStylesOff is this:

11111111 11111111 11111111 11111011

the result of using the AND operator with the original style and lngStylesOff will be this:

10001000 10001010 10101011 01101001

The value in lngStylesOn contains 0s in all positions except the ones you want turned on, which contain 1s. If

Return Main Page Previous Page Next Page

®Online Book Reader