Access Cookbook - Ken Getz [264]
Import the module basShell from 12-05.MDB into your own application. This module is completely self-contained and includes a number of functions that will set up the DDE conversation, do the work or retrieve the information you need, and then terminate the conversation. Because we've hidden all the details of the DDE, you needn't worry about getting all the syntax and parameters correct.
Depending on your needs, call one or more of the wrapper procedures described in Table 12-4. All of these functions are covered in detail in Recipe 12.4.3 (see Table 12-9).
Table 12-4. Procedures in basShell to aid in using DDE between Access and Windows shell
Procedure
Purpose
acbPMCreateGroup
Create a group, given a group name and a pathname for the group file.
acbPMCreateItem
Create a new item, given the group name, the item name, the command line, the default directory, and whether or not to run the application minimized.
acbPMDeleteGroup
Delete a group, given the name of the group to delete.
acbPMDeleteItem
Delete an item from a group, given the name of the group and the name of the item.
acbPMGetGroups
Fill a dynamic array with all the groups.
acbPMGetItems
Fill a dynamic array with all the items for a particular group.
acbPMShowGroup
Show a particular group, given the name of the group and the window mode to use.
acbPMShowMessages
Allow callers outside this module to show or hide messages. Pass in True to show messages, False to hide them (no DDE involved).
Discussion
The Windows shell supports two operations: you can either request information using the DDERequest function (Table 12-5 lists the DDERequest items) or execute actions using the DDEExecute subroutine (Table 12-6 lists the most useful subset of the shell's DDEExecute command-string interface). DDE conversations between Access and the shell involve three steps:
Initiate the conversation.
Perform the necessary tasks.
Terminate the conversation.
Retrieving information from the Windows shell
Table 12-5 describes the two groups of information you can request from Windows. The sample form, frmShell, uses both to fill its two list boxes.
Table 12-5. DDERequest topics for the Windows shell
To retrieve
Program
Topic
Item
Returns
List of groups
PROGMAN, or Folders
PROGMAN, or AppProperties
PROGMAN
List of existing groups, separated with CR/LF pair
List of items in a group
PROGMAN, or Folders
PROGMAN, or AppProperties
List of items in the specified group, separated with CR/LF pair To retrieve a list of groups from Windows using the Access DDERequest function, you must first initiate a conversation with the PROGMAN program on the PROGMAN topic, requesting information on the PROGMAN item; even if you use the undocumented "Folders" program name and "AppProperties" topic, it still expects you to request information on the PROGMAN item. The DDERequest call returns a carriage-return/line-feed (CR/LF) delimited string of group names. It's up to your code to pull apart the list of groups and place them into whatever data structure is most convenient for you. To simplify this task, you can use the acbPMGetGroups function in basShell. It accepts, as a parameter, a dynamic array to fill in with the list of groups. This function performs the DDERequest for you and calls the private CopyToArray function to break apart the returned stream of groups and fill the array you've sent it. It returns the number of items in the array. Its source code is: Public Function acbPMGetGroups(avarGroups( ) As Variant) ' Fill a dynamic array with all the Program Manager groups. Dim lngChannel As Long Dim strGroups As String Dim intCount As Integer On Error GoTo HandleErr ' Most replacement shells will start PROGMAN for you if you attempt ' to start up a DDE conversation with it. That is, you won't need ' to Shell( ) PROGMAN if you're using a replacement shell. lngChannel = DDEInitiate("PROGMAN", "PROGMAN") strGroups = DDERequest(lngChannel, "PROGMAN") intCount = CopyToArray(strGroups,