The information in this article applies to:
- Standard and Professional Editions of Microsoft Visual Basic for
Windows, versions 2.0 and 3.0
- Microsoft Visual Basic for Windows, version 1.0
SUMMARY
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;
and 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
MORE INFORMATION
Perform the following steps to produce an application that manipulates
Program Manager using DDE:
- Start Visual Basic or if Visual Basic is already running, choose New
Project from the File menu (ALT, F, N). Form1 is created by default.
- Add a Textbox control (Text1) to Form1.
- Add a Label control (Label1) to Form1 and change the caption to Group.
- Add a Textbox control (Text2) to Form1 and change the name to GGroup.
- Add a Label control (Label2) to Form1 and change the caption to Item.
- Add a Textbox control (Text3) to Form1 and change the name to GItem.
- Add a Label control (Label3) to Form1 and change the caption to Command
Line.
- Add a Textbox control (Text4) to Form1 and change the name to ItemExe.
- Add a Command Button control (Command1) to Form1 and name it CGroup for
create group.
- Add the following code to the CGroup_Click event of Form1:
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 a Command Button control (Command2) to Form1 and name it DGroup for
Delete Group.
- Add the following code to the DGroup_Click event of Form1:
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 a Command Button control (Command3) to Form1 and name it SGroup
for ShowGroup.
- Add the following code to the SGroup_Click event of Form1:
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 a Command Button control (Command4) to Form1 and name it Reload.
- Add the following code to the Reload_Click event of Form1:
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 a Command Button control (Command5) to Form1 and name it
AItem for add item.
- Add the following code to the AItem_Click event of Form1:
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 forces the group you want the
'*** action taken to get the focus.
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 a Command Button control (Command6) to Form1 and name it
DItem for delete item.
- Add the following code to the DItem_Click event of Form1:
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 forces the group you want the action
'*** taken to get the focus.
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 a Command Button control (Command7) to Form1 and name it
RItem for replace item.
- Add the following code to the RItem_Click event of Form1:
Sub RItem_Click ()
Dim cmd As String
On Error GoTo RIError
text1.LinkMode = 0
text1.LinkTopic = "Progman|Progman"
text1.LinkMode = 2
'*** ShowGroup forces the group you want the action taken on
'*** to get the focus.
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
- From the Run menu, choose Start (ALT, R, S) or press the F5 key to run
the program. Enter the group you want created in the GGroup textbox
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 textbox. Enter the item you want added in the
GItem textbox and enter the command line in the ItemExe textbox.
The item will now be in the group you specified.
For more information, refer to 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.
|