Article ID: 138800
Article Last Modified on 1/8/2003
APPLIES TO
- Microsoft Visual Basic 4.0 Professional Edition
- Microsoft Visual Basic 4.0 16-bit Enterprise Edition
This article was previously published under Q138800
SUMMARY
This article shows by example how to manipulate groups and items in Program Manager by using DDE.
MORE INFORMATION
Program Manager has a DDE command-string interface that allows other applications to:
- Create, display, delete, and reload groups.
- Add items to groups.
- Replace items in groups.
- Delete items from groups.
- Close Program Manager.
The following commands perform these actions:
CreateGroup Reload (Windows 3.1 only) DeleteGroup ShowGroup ReplaceItem (Windows 3.1 only) DeleteItem (Windows version 3.1 only) AddItem
Step-by-Step Example
Perform the following steps to produce an application that manipulates Program Manager using DDE:
- Start a new project in Visual Basic. Form1 is created by default.
Add the following controls to Form1, setting properties as indicated:
Control Property Value ---------------------------------------------------------------- Text box (Text1) Label (Label1) Caption Group Text box (Text2) Name GGroup Label (Label2) Caption Item Text box (Text3) Name GItem Label (Label3) Caption Command Line Text box (Text4 Name ItemExe Command button (Command1) Name CGroup (for create group) Command button (Command2) Name DGroup (for delete group) Command button (Command3) Name SGroup (for show group) Command button (Command4) Name Reload Command button (Command5) Name AItem (for add item) Command button (Command6) Name DItem (for delete item) Command button (Command7) Name RItem (for replace item)
Add the following code to the CGroup_Click event:
Private Sub CGroup_Click () Dim cmd As String On Error GoTo CGError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 cmd = "[CreateGroup(" + GGroup.Text + ")]" text1.LinkExecute cmd CGDone: text1.LinkMode = 0 Exit Sub CGError: MsgBox "Error Adding Group" Resume CGDone End Sub
Add the following code to the DGroup_Click event:
Private Sub DGroup_Click () Dim cmd As String On Error GoTo DGError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 cmd = "[DeleteGroup(" + GGroup.Text + ")]" text1.LinkExecute cmd DGDone: text1.LinkMode = 0 Exit Sub DGError: MsgBox "Error Deleting Group" Resume DGDone End Sub
Add the following code to the SGroup_Click event:
Private Sub SGroup_Click () Dim cmd As String On Error GoTo SGError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 cmd = "[ShowGroup(" + GGroup.Text + ", 2" + ")]" text1.LinkExecute cmd cmd = "[ShowGroup(" + GGroup.Text + ", 1" + ")]" text1.LinkExecute cmd SGDone: text1.LinkMode = 0 Exit Sub SGError: MsgBox "Error Showing Group" Resume SGDone End Sub
Add the following code to the Reload_Click event:
Private Sub Reload_Click () Dim cmd As String On Error GoTo RLError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 cmd = "[Reload(" + GGroup.Text + ")]" text1.LinkExecute cmd RLDone: text1.LinkMode = 0 Exit Sub RLError: MsgBox "Error Reloading Group" Resume RLDone End Sub
Add the following code to the AItem_Click event:
Private Sub AItem_Click () Dim cmd As String On Error GoTo AIError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 '*** The ShowGroup is necessary because AddItem changes the group '*** with the focus. ShowGroup gives the focus to the group where '*** you want the action taken. If (Len(GGroup.Text) > 0) Then cmd = "[ShowGroup(" + GGroup.Text + ", 2" + ")]" text1.LinkExecute cmd cmd = "[ShowGroup(" + GGroup.Text + ", 1" + ")]" text1.LinkExecute cmd End If cmd = "[Additem(" + ItemExe.Text + "," + GItem.Text + ")]" text1.LinkExecute cmd AIDone: text1.LinkMode = 0 Exit Sub AIError: MsgBox "Error adding Item" Resume AIDone End Sub
Add the following code to the DItem_Click event:
Private Sub DItem_Click () Dim cmd As String On Error GoTo DIError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 '*** ShowGroup is necessary because DeleteItem changes the group '*** with the focus. ShowGroup gives the focus to the group where '*** you want the action taken. If (Len(GGroup.Text) > 0) Then cmd = "[ShowGroup(" + GGroup.Text + ", 2" + ")]" text1.LinkExecute cmd cmd = "[ShowGroup(" + GGroup.Text + ", 1" + ")]" text1.LinkExecute cmd End If cmd = "[DeleteItem(" + GItem.Text + ")]" text1.LinkExecute cmd DIDone: text1.LinkMode = 0 Exit Sub DIError: MsgBox "Error Deleting Item" Resume DIDone End Sub
Add the following code to the RItem_Click event:
Private Sub RItem_Click () Dim cmd As String On Error GoTo RIError text1.LinkMode = 0 text1.LinkTopic = "Progman|Progman" text1.LinkMode = 2 '*** ShowGroup gives the focus to the group where you want the action '*** taken. If (Len(GGroup.Text) > 0) Then cmd = "[ShowGroup(" + GGroup.Text + ", 2" + ")]" text1.LinkExecute cmd cmd = "[ShowGroup(" + GGroup.Text + ", 1" + ")]" text1.LinkExecute cmd End If cmd = "[ReplaceItem(" + GItem.Text + ")]" text1.LinkExecute cmd cmd = "[Additem(" + ItemExe.Text + "," + GItem.Text + ")]" text1.LinkExecute cmd RIDone: text1.LinkMode = 0 Exit Sub RIError: MsgBox "Error Replacing Item" Resume RIDone End Sub
- On the Run menu, click Start (ALT, R, S) or press the F5 key to run the program. Enter the group you want created in the GGroup box, and click the Create Group button. You will now see the group you created in Program Manager. To add an item to a group, enter the group in the GGroup box. Enter the item you want added in the GItem box, and enter the command line in the ItemExe box. The item will now be in the group you specified.
REFERENCES
For more information, please see the "Programmers Reference, Volume 1: Overview Microsoft Windows SDK," chapter 17, "Shell Dynamic DataExchange Interface." Also, look in the Windows SDK Help file in the Progman topic.
Additional query words: 4.00 vb4win vb416
Keywords: KB138800