Microsoft KB Archive/104943

From BetaArchive Wiki
Knowledge Base


VB3 Manipulate Groups & Items in Program Manager Using DDE

Article ID: 104943

Article Last Modified on 12/9/2003



APPLIES TO

  • Microsoft Visual Basic 2.0 Standard Edition
  • Microsoft Visual Basic 3.0 Professional Edition
  • Microsoft Visual Basic 2.0 Professional Edition
  • Microsoft Visual Basic 3.0 Professional Edition



This article was previously published under Q104943

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:

  1. 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.
  2. Add a Textbox control (Text1) to Form1.
  3. Add a Label control (Label1) to Form1 and change the caption to Group.
  4. Add a Textbox control (Text2) to Form1 and change the name to GGroup.
  5. Add a Label control (Label2) to Form1 and change the caption to Item.
  6. Add a Textbox control (Text3) to Form1 and change the name to GItem.
  7. Add a Label control (Label3) to Form1 and change the caption to Command Line.
  8. Add a Textbox control (Text4) to Form1 and change the name to ItemExe.
  9. Add a Command Button control (Command1) to Form1 and name it CGroup for create group.
  10. 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
                            
  11. Add a Command Button control (Command2) to Form1 and name it DGroup for Delete Group.
  12. 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
                            
  13. Add a Command Button control (Command3) to Form1 and name it SGroup for ShowGroup.
  14. 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
                            
  15. Add a Command Button control (Command4) to Form1 and name it Reload.
  16. 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
                            
  17. Add a Command Button control (Command5) to Form1 and name it AItem for add item.
  18. 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
                            
  19. Add a Command Button control (Command6) to Form1 and name it DItem for delete item.
  20. 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
                            
  21. Add a Command Button control (Command7) to Form1 and name it RItem for replace item.
  22. 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
                            
  23. 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.


Additional query words: 1.00 2.00 3.00

Keywords: kbcode KB104943