Microsoft KB Archive/109394

From BetaArchive Wiki

Article ID: 109394

Article Last Modified on 5/6/2003



APPLIES TO

  • Microsoft Access 1.0 Standard Edition
  • Microsoft Access 1.1 Standard Edition
  • Microsoft Access 2.0 Standard Edition



This article was previously published under Q109394

SUMMARY

Advanced: Requires expert coding, interoperability, and multiuser skills.

This article describes a sample Access Basic function called CreatePROGMANIcon() that you can use to create an icon in the Microsoft Windows Program Manager using dynamic data exchange (DDE).

This article assumes that you are familiar with Access Basic and with creating Microsoft Access applications using the programming tools provided with Microsoft Access. For more information on Access Basic, please refer to the "Introduction to Programming" manual in Microsoft Access version 1.x, or the "Building Applications" manual, Chapter 3, "Introducing Access Basic" in version 2.0.

MORE INFORMATION

To set up the CreatePROGMANIcon() function, create a new module and enter the code below.

NOTE: In the following sample code, an underscore (_) is used as a line- continuation character. Remove the underscore from the end of the line when re-creating this code in Access Basic.

   Option Explicit

   '**************************************************
   ' FUNCTION: CreatePROGMANIcon
   '
   ' PURPOSE:
   '   To create an icon in the Windows Program Manager.
   '
   ' ARGUMENTS:
   '   CommandLine - The command line argument to execute
   '                 when the icon is double-clicked.
   '   IconText    - The text to appear under the icon.
   '   GroupName   - The name of the group to place the
   '                 icon in.
   ' RESULT:
   '   An icon is placed in the specified group. If the
   '   group does not exist, a new group is created.
   '
   ' *************************************************
   Function CreatePROGMANIcon (CommandLine$, IconText$, GroupName$)
      Dim ChanNum As Integer
      Dim Groups As String
      Dim Exe As String

      ' Begin a DDE conversation with Program Manager.
      ChanNum = DDEInitiate("PROGMAN", "PROGMAN")

      ' Request a tab delimited list of Program Manager groups.
      Groups = DDERequest(ChanNum, "Progman")

      ' See if the requested group exists in the list.
      ' If not, create the group.
      If Not InStr(1, Groups, GroupName) Then
         DDEExecute ChanNum, "[CreateGroup(" & GroupName & ")]"
      End If

      ' Add an icon to the group with the specified text underneath.
      Exe = "[AddItem(" & CommandLine & ", " & IconText & ",,)]"
      DDEExecute ChanNum, Exe
      DDETerminate ChanNum

   End Function
                


How to Use the CreatePROGMANIcon() Function

Type the command below in an Immediate window and then press ENTER.

NOTE: In the following example, an underscore (_) is used as a line- continuation character. Remove the underscore when re-creating this example.

   ? CreatePROGMANIcon("C:\WINDOWS\NOTEPAD.EXE C:\AUTOEXEC.BAT", _
      "AUTOEXEC", "MAIN")
                


The sample command above uses the CreatePROGMANIcon() function to add an icon to the Main group in Program Manager. The icon will open the Windows Notepad text editor and load the C:\AUTOEXEC.BAT file into Notepad.

Note that when the icon is created, Program Manager uses the default icon supplied with the application specified in the command line. The following function is a modified version of the CreatePROGMANIcon() function with two additional arguments. These arguments are IconFile, which specifies the name of a file containing custom icons, and IconNum, which specifies which icon in the IconFile to use. Note that if you specify "", or null, for both of these arguments, the default icon will be used.

   Function CreatePROGMANIcon2 (CommandLine$, IconText$, GroupName$, _
      IconFile$, IconNum$)

      Dim ChanNum As Integer
      Dim Groups As String
      Dim Exe As String

      ' Begin a DDE conversation with Program Manager.
      ChanNum = DDEInitiate("PROGMAN", "PROGMAN")

      ' Request a tab delimited list of Program Manager groups.
      Groups = DDERequest(ChanNum, "Progman")

      ' See if the requested group exists in the list.
      ' If not, create the group.
      If Not InStr(1, Groups, GroupName) Then
         DDEExecute ChanNum, "[CreateGroup(" & GroupName & ")]"
      End If

      ' Add an icon to the group with the specified text underneath.
      Exe$ = "[AddItem(" & CommandLine & ", " & IconText & ", _
             " & IconFile & ", " & IconNum & ")]"
      DDEExecute ChanNum, Exe
      DDETerminate ChanNum

   End Function
                


The following sample command uses the fourth icon in the MORICONS.DLL file that is supplied with Windows. This file contains multiple custom icons:

   CreatePROGMANIcon2("C:\TEST\TEST.EXE ","My App","My Group",_
      "C:\WINDOWS\MOREICONS.DLL","4")
                


The next sample command uses an icon in an .ICO file. Since there is only one icon in each .ICO file, leave the IconNum argument empty:

   CreatePROGMANIcon2("C:\TEST\TEST.EXE ","My App","My Group",_
      "C:\ICONS\MY.ICO","")
                

REFERENCES

Windows Software Development Kit "Guide to Programming," pages 19-22

For more information about DDE and Program Manager, please see the following article in the Microsoft Knowledge Base:

119724 ADT2: How to Add an Icon to Program Manager Using DDE

Keywords: kbhowto kbinterop KB109394