How to Use DDE with Visual Basic and Windows Program Manager

Last reviewed: January 23, 1996
Article ID: Q142822
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 demonstrates how to send dynamic data exchange (DDE) interface commands to the Microsoft Windows Program Manager from Microsoft Visual Basic for Windows using DDE.

The interface commands available through DDE with the Windows Program Manager are as follows:

   CreateGroup(GroupName,GroupPath)
   ShowGroup(GroupName,ShowCommand)
   AddItem(CommandLine,Name,IconPath,IconIndex,XPos,YPos)
   DeleteGroup(GroupName)
   ExitProgman(bSaveState)

A full explanation of the above commands can be found in Chapter 22 of the "Microsoft Windows Software Development Kit Guide to Programming" version 3.1 manual. The Microsoft Windows Software Development Kit can be found in the MSDN/VB Starter Kit which is distributed with the Professional and Enterprise editions of Visual Basic 4.0.

An application can also obtain a list of Windows groups from the Windows Program Manager by issuing a LinkRequest to the "PROGMAN" item.

MORE INFORMATION

The following program demonstrates how to use four of the five Windows Program Manager DDE interface commands and the one DDE request:

  1. Run Visual Basic for Windows, or on the File menu, click New Project (ALT, F, N) if Visual Basic for Windows is already running. Form1 is created by default.

  2. Create the following controls with the given properties on Form1:

          Object     Name         Caption
          ------     --------     -------
          TextBox    Text1
          Button     Command1     Make
          Button     Command2     Delete
          Button     Command3     Request
    
        (In Visual Basic version 1.0 for Windows, set the CtlName Property
         for the above objects instead of the Name property.)
    
    

  3. Add the following code to the Command1_Click event:

       Private Sub Command1_Click ()
          Text1.LinkTopic = "ProgMan|Progman"
          Text1.LinkMode = 2               ' Establish manual link.
    
          Text1.LinkExecute "[CreateGroup(Test Group)]"
              ' Make a group in Windows Program Manager.
    
          Text1.LinkExecute "[AddItem(c:\vb\vb.exe, Visual Basic)]"
              ' Add an item to that group.
    
          Text1.LinkExecute "[ShowGroup(Test Group, 7)]"
              ' Iconize the group and focus to VB application.
    
       On Error Resume Next  ' Disconnecting link with Windows Program
       Text1.LinkMode = 0    '  Manager causes an error in Windows 3.0.
                 ' This is a known problem with Windows Program Manager.
       End Sub
    
    

  4. Add the following code to the Command2_Click event:

       Private Sub Command2_Click ()
          Text1.LinkTopic = "ProgMan|Progman"
          Text1.LinkMode = 2          ' Establish manual link.
    
          Text1.LinkExecute "[DeleteGroup(Test Group)]"
              ' Delete the group and all items within it.
    
          On Error Resume Next  ' Disconnecting link with Windows Program
          Text1.LinkMode = 0    '  Manager causes an error in Windows 3.0.
                     ' This is a known problem with Windows Program Manager.
       End Sub
    
    

  5. Add the following code to the Command3_Click event:

       Private Sub Command3_Click ()
          Text1.LinkTopic = "ProgMan|Progman"
          Text1.LinkItem = "PROGMAN"
          Text1.LinkMode = 2      ' Establish manual link.
          Text1.LinkRequest       ' Get a list of the groups.
    
          On Error Resume Next  ' Disconnecting link with Windows Program
          Text1.LinkMode = 0    '  Manager causes an error in Windows 3.0.
                 ' This is a known problem with Windows Program Manager.
       End Sub
    
    

  6. Press the F5 key to run the program.

  7. Click the Make button, and then click the Delete button. Note the result.

  8. Click the Request button. This puts a list of the groups in the Windows Program Manager to be placed in the text box. The individual items are delimited by a carriage return plus linefeed.

As noted in the Windows Software Development Kit (SDK) manual mentioned above, the ExitProgman() command only works if the Windows Program Manager is NOT the shell (the startup program when you start Windows).

For a more comprehensive explanation of the CreateGroup(), ShowGroup(), AddItem(), DeleteGroup(), and ExitProgman() commands, query on the following words in the Microsoft Knowledge Base:

   DDE and CreateGroup


Additional reference words: 1.00 2.00 3.00 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: January 23, 1996
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.