Retrieving Groups & Items from Program Manager Using DDE in VB

Last reviewed: June 21, 1995
Article ID: Q112384
The information in this article applies to:

- Standard and Professional Editions of Microsoft Visual Basic

  programming system for Windows, versions 1.0, 2.0, and 3.0

SUMMARY

Program Manager (Progman) has a DDE command-string interface that allows other applications to view the groups and items that currently exist within Progman.

MORE INFORMATION

Perform the following steps to produce an application that will retrieve the group and items from Progman by using DDE:

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

  2. Add two Text box controls (tGroups and tItems) to Form1. Set the visible property on both to false. The DDE link needs these controls.

  3. Add two Combo box controls (ComGroups and ComItems) to Form1.

  4. Add a Command button (cGroups) to Form1 and change the caption property to Groups.

  5. Add the following code to the cGroups_Click () event:

       Sub cGroups_Click ()
          Dim sGroups As String
          Dim pos As Integer
          On Error GoTo GError
          tGroups.LinkMode = 0
          tGroups.LinkTopic = "Progman|Progman"
          tGroups.LinkMode = 2
          tGroups.LinkItem = "groups"
          tGroups.LinkRequest
    
          ' Parse groups that come back:
          sGroups = tGroups.Text
          pos = InStr(1, sGroups, Chr(13))
          While pos
             ComGroups.AddItem RTrim$(Mid$(sGroups, 1, pos - 1))
             sGroups = LTrim$(Mid$(sGroups, pos + 2))
             ' The + 2 on the previous line gets past the line feed chr(10)
             pos = InStr(1, sGroups, Chr(13))
          Wend
    
          ' Select first member in combo box:
          ComGroups.ListIndex = 1
          GDone:
             tGroups.LinkMode = 0
             Exit Sub
          GError:
             MsgBox "Error in getting groups"
             Resume GDone
       End Sub
    
    

  6. Add another Command button (cItems) to Form1, and change the caption to Items.

  7. Add the following code to the cItems_Click () event:

       Sub cItems_Click ()
          Dim sItems As String
          On Error GoTo IError
    
          ' Clear the combo box:
          ComItems.Clear
          If (Len(ComGroups.Text)) Then
             tItems.LinkMode = 0
             tItems.LinkTopic = "Progman|Progman"
             tItems.LinkMode = 2
             tItems.LinkItem = ComGroups.Text
             tItems.LinkRequest
    
             ' Parse items that come back:
             sItems = tItems.Text
             pos = InStr(1, sItems, Chr(13))
             While pos
                ComItems.AddItem RTrim$(Mid$(sItems, 1, pos - 1))
                sItems = LTrim$(Mid$(sItems, pos + 2))
                ' The + 2 on the previous line gets past the line feed chr(10)
                pos = InStr(1, sItems, Chr(13))
             Wend
          End If
    
          ' Select first member in combo box:
          ComItems.ListIndex = 1
          IDone:
             tItems.LinkMode = 0
             Exit Sub
          IError:
             MsgBox "Error in getting items"
             Resume IDone
       End Sub
    
    

  8. From the Run menu, choose Start (ALT, R, S) or press the F5 key to run the program. Press the Groups button and all the groups on Progman will be loaded into the ComGroups Combo box. Then press the Items button and all the items in the group selected in the ComGroups Combo box will be put into the ComItems Combo box.

REFERENCES

More information can be found in:

  • "Programmers Reference, Volume 1: Overview Microsoft Windows SDK," Chapter 17, "Shell Dynamic Data Exchange Interface DDEML."
  • Progman topic in the Windows SDK Help menu.


Additional reference words: 1.00 2.00 3.00 interop icon
KBCategory: kbinterop kbprg kbcode
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: June 21, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.