Online Book Reader

Home Category

Access Cookbook - Ken Getz [267]

By Root 1944 0

DDEExecutePM = True

ExitHere:

On Error Resume Next

DDETerminate lngChannel

Err.Clear

Exit Function

HandleErr:

If Not mfHideMessages Then

MsgBox Err.Number & ": " & Err.Description, , "DDEExecutePM"

End If

DDEExecutePM = False

Resume ExitHere

End Function

Given a string to execute, this code initiates the DDE channel, uses DDEExecute to execute the command, and then terminates the connection. If all goes according to plan, the procedure returns a True value. If an error occurs, it displays a message box (unless you've used the acbPMShowMessages procedure to disable warning messages) and then returns False.

Table 12-9 lists the parameters for the wrapper procedures in basShell. Each of these procedures (except acbPMShowMessages) returns True if the function succeeded, or False if it failed. Unless you've called the acbPMShowMessages subroutine to disable messages, a message will appear before deleting a group or item or if any error occurs.

Table 12-9. Parameters for the wrapper procedures in basShell

Procedure

Parameter

Data type

Parameter description

acbPMCreateGroup

varName

Variant

Name of the new group.

varGroupPath

Variant

Name of the group file (can be Null, in which case Windows uses a name of its own choosing).

acbPMCreateItem

varGroup

Variant

Name of the group in which to create the new item.

varName

Variant

Descriptive name for the new item; appears under the icon.

varCommandLine

Variant

Command line to execute when this icon is chosen. Cannot be Null.

varDirectory

Variant

Default (working) directory when the application starts up.

varMinimized

Variant

Logical value: run the app minimized?

acbPMDeleteGroup

varName

Variant

Group to delete.

acbPMDeleteItem

varGroup

Variant

Group from which to delete the item.

varName

Variant

Name of the item to delete.

acbPMShowGroup

varName

Variant

Name of the group to show.

intMode

Integer

Window mode, as listed in Table 12-8.

acbPMShowMessages

fShow

Integer

Logical value: display messages during DDE wrapper functions? If True, functions use message box if errors occur and when deleting items. This subroutine sets a module global variable, so you need to call it only once per session.

For example, to use the wrapper functions to add an icon to the My Group group that will run C:\EDIT\MYEDIT.EXE minimized with the description My Editor (as in the example that called AddItem directly), you could use code like this:

Dim fSuccess As Boolean

' Disable error messages.

acbPMShowMessages False

fSuccess = acbPMCreateItem("My Group", "My Editor", _

"C:\EDIT\MYEDIT.EXE", Null, True)

If Not fSuccess Then MsgBox "Unable to create new item!"

This example also calls acbPMShowMessages to disable error messages from within acbCreateItem, so the code fragment itself can handle them.

For examples of each of the wrapper functions, check out the code in frmShell's module.

Comments


Though this solution covers a great deal more than the original question required, all the information here will be useful to Access programmers working with the DDE interface to the Windows shell.

The sample form, frmShell, is not only a good example of using DDE to converse with Windows, it's also a useful tool on its own. Because it allows you to see what's in each group without having to open and close each group's window, it's a quick and easy way to clean out your groups. Of course, some extra work would be required for it to be a really useful tool, but it's a good start.

In 16-bit applications, DDEInitiate returns a short integer (16-bit) handle. In Access 95 and later (and other 32-bit applications), this function returns a long integer (32-bit) handle. If you have existing code that uses DDE, you'll want to convert the variables containing the return values into long integers.

The Windows shell has an undocumented DDE application → topic pair that is not supported by the original Program Manager or any of the major third-party shell substitutes: Folders → AppProperties. This syntax seems to be

Return Main Page Previous Page Next Page

®Online Book Reader