ID Number: Q76551
1.00
WINDOWS
Summary:
This article demonstrates how to send DDE interface commands to the
Windows Program Manager from Visual Basic using dynamic data exchange
(DDE).
The interface commands available through DDE with Program Manager are
as follows:
CreateGroup(GroupName,GroupPath)
ShowGroup(GroupName,ShowCommand)
AddItem(CommandLine,Name,IconPath,IconIndex,XPos,YPos)
DeleteGroup(GroupName)
ExitProgman(bSaveState)
A full explanation of the above commands can be found in Chapter 22,
pages 19-22 of the "Microsoft Windows Software Development Kit Guide
to Programming" version 3.0 manual.
An application can also obtain a list of Windows groups from the
Program Manager by issuing a LinkRequest to the "PROGMAN" item.
This information applies to Microsoft Visual Basic version 1.0 for
Windows and to Microsoft Windows version 3.0.
More Information:
The following program demonstrates how to use four of the five Program
Manager DDE interface commands and the one DDE request:
1. Run Visual Basic, or from the File menu, choose New Project (ALT,
F, N) if Visual Basic is already running. Form1 is created by
default.
2. Create the following controls with the given properties on Form1:
Object CtrlName Caption
------ -------- -------
TextBox Text1
Button Command1 Make
Button Command2 Delete
Button Command3 Request
3. Add the following code to the Command1 Click event:
Sub Command1_Click ()
Text1.LinkTopic = "ProgMan|Progman"
Text1.LinkMode = 2 'Establish Cold link.
Text1.LinkExecute "[CreateGroup(Test Group)]"
'Make a group in Program Manager.
Text1.LinkExecute "[AddItem(c:\vb\vb.exe, Visual Basic)]"
'Add an item to that group.
Text1.LinkExecute "[ShowGroup(Test Group, 7)]"
'Iconize the group and focus to VB application.
On Error Resume Next 'Disconnecting link with Program
Text1.LinkMode = 0 'Manager causes an error.
'This is a known problem with Program Manager.
End Sub
4. Add the following code to the Command2 Click event:
Sub Command2_Click ()
Text1.LinkTopic = "ProgMan|Progman"
Text1.LinkMode = 2 'Establish Cold link.
Text1.LinkExecute "[DeleteGroup(Test Group)]"
'Delete the group and all items within it.
On Error Resume Next 'Disconnecting link with Program
Text1.LinkMode = 0 'Manager causes an error.
'This is a known problem with Program Manager.
End Sub
5. Add the following code to the Command3 Click event:
Sub Command3_Click ()
Text1.LinkTopic = "ProgMan|Progman"
Text1.LinkItem = "PROGMAN"
Text1.LinkMode = 2 'Establish Cold link.
Text1.LinkRequest 'Get a list of the groups
On Error Resume Next 'Disconnecting link with Program
Text1.LinkMode = 0 'Manager causes an error.
'This is a known problem with Program Manager.
End Sub
5. Press F5 to run the program.
6. Choose the Make button, then choose the Delete button. Note the
result.
7. Choose the Request button. This will put a list of the groups
in Program Manager to be placed in the text box. The individual
items are delimited by a carriage return plus linefeed.
As noted in the Windows 3.0 Software Development Kit (SDK) manual
mentioned above, the ExitProgram() command will only work if Windows
Program Manager is NOT the shell (the startup program when you start
Windows).
For a more comprehensive explanation of the CreateGroup, ShowGroup,
AddItem, DeleteGroup, and ExitProgman commands, query on the
following words in the Microsoft Knowledge Base:
DDE and CreateGroup
Additional reference words: 1.00 3.00