Access Cookbook - Ken Getz [263]
TIP
You'll find several references to Program Manager and PROGMAN throughout this solution, as well as the use of the group/item notation rather than folder/shortcut, but the effect is the same either way: you can create groups and items in the Program Manager or in the Windows shell, depending on your environment.
Figure 12-7. frmShell allows you to communicate with the Windows shell via DDE
Once you select a group from the list on the left in Figure 12-7, the form will display the group's items in the list on the right. If you select the first item in the righthand list—the group itself—the form will display the information Windows stored about that group. Once you've selected a group in the righthand list box, you can click the Show button to have Windows display that group. The code attached to the Show button requests Windows to open the group window using style 3 (see Table 12-8 for a list of window styles). As described later, in the sidebar Switching Focus," Windows may grab the focus, depending on the previous state of the group window you've selected.
TIP
The shell DDE interface does not support long filenames, and attempts to enter long filenames will fail with an error. The example form displays long filenames using the 8.3 short version of the name—usually six characters, followed by a "~1" (or a higher digit).
Select an item in the group (any row except the first in the righthand list box), and the form will display all the information that Windows stores about that item. Figure 12-8 shows frmShell with an item selected.
Figure 12-8. frmShell with a group selected and its information displayed
With either a group or an item selected, you can create or delete a group or an item. If you've selected a group, pressing the Delete button will instruct Windows to delete that group; if you've selected an item, Windows will delete that item. Regardless of what's selected, pressing the Create button will pop up a dialog asking whether you want to create a new item or a new group. Either choice will pop up the appropriate dialog requesting the necessary information.
The following sections describe how to use the sample forms in your own applications, and then explain most of the DDE interface to the Windows shell. Although more DDE options are available, the most useful tasks can be accomplished with the tools provided here.
Using the sample forms
To include the sample forms from 12-05.MDB in your own applications, follow these steps:
Import the objects shown in Table 12-3 into your application.
Table 12-3. Objects to import from 12-05.MDB
Object
Name
Purpose
Form
frmNew
Choose new group or new item.
Form
frmNewGroup
Enter new group information.
Form
frmNewItem
Enter new item information.
Form
frmShell
Main form.
Module
basShell
Perform DDE conversations with Windows shell.
Module
basSortArray
Sort arrays (list of program groups).
Module
basToken
Pull apart strings (item and group information on frmShell).
Load and run frmShell.
As described previously, you can use the form to manipulate shell groups and items from your Access application. If you want to use only some parts of frmShell in your application instead of the whole thing, that's fine too. If you use the group list (lstGroups), you'll also need to include the function that fills it, FillGroups. If you want the item list (lstItems), you'll also need FillItems. In addition, place code in lstGroup's AfterUpdate event that requeries lstItems once you've made a selection in lstGroups. You'll end up with an event procedure like this:
Private Sub lstGroups_AfterUpdate ( )
Me.lstItems.Requery
End Sub
To use other bits and pieces of the functionality of frmShell, you'll need to investigate its form module.
Using DDE with the Windows shell
If your main interest is simply to use DDE to control the Windows shell, follow these