How to Manipulate Groups & Items in Program Manager Using DDE

Last reviewed: December 8, 1995
Article ID: Q138800
The information in this article applies to:
  • Professional and Enterprise Editions of Microsoft Visual Basic, 16-bit only, for Windows, version 4.0

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:

  1. Start a new project in Visual Basic. Form1 is created by default.

  2. 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)
    
    

  3. 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
    
    

  4. 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
    
    
    

  5. 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
    
    

  6. 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
    
    

  7. 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
    
    

  8. 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
    
    

  9. 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
    
    

  10. 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 reference words: 4.00 vb4win vb416
KBCategory: kbinterop kbprg kbcode kbhowto
KBSubcategory: IAPDDE


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: December 8, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.