home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #1 / monster.zip / monster / PROG_C / CENVIW9.ZIP / PROGMAN.LIB < prev    next >
Text File  |  1994-03-08  |  13KB  |  314 lines

  1. // ProgMan.lib - Library for interacting with Program Manager
  2. // ver.1         through DDE.
  3. //
  4. //
  5. //**** IsProgmanRunning()
  6. // SYNTAX: bool IsProgmanRunning()
  7. // RETURN: Returns true if Progman DDE is working
  8. // NOTE: This routines simply calls ConnectToProgman() and CloseProgmanConnection()
  9. //
  10. //
  11. //**** ConnectToProgman(): Initialize DDE Client connection to Progman
  12. // SYNTAX: bool ConnectToProgman()
  13. // RETURN: Return TRUE if able to connect, else False
  14. // NOTE: The other funcitons in this library will connect by themselves if
  15. //       this routine has not already been called, but if you are doing
  16. //       a lot of Program Manager calls then it will go faster to call this
  17. //       once in the beginning and call CloseProgmanConnection() once at the end.
  18. //
  19. //
  20. //**** CloseProgmanConnection(): terminate DDE Client connection
  21. // SYNTAX: void CloseProgmanConnection()
  22. // NOTE: This should be called once for each ConnectToProgman() call.  See
  23. //       ConnectToProgman() for more notes.
  24. //
  25. //
  26. //**** CreateGroup(): Create group in Program Mnager
  27. // SYNTAX: bool CreateGroup(string GroupName[,bool CommonGroupFlag])
  28. // WHERE: GroupName: Text name for the new group
  29. //        CommonGroupFlag: False for personal group, else CommonGroup; default=False
  30. // RETURN: False on error, else success
  31. //
  32. //
  33. //**** DeleteGroup(): Delete group from Program Mnager
  34. // SYNTAX: bool DeleteGroup(string GroupName[,bool CommonGroupFlag])
  35. // WHERE: GroupName: Text name for the existing group
  36. //        CommonGroupFlag: False for personal group, else CommonGroup; default=False
  37. // RETURN: False on error, else success
  38. //
  39. //
  40. //**** ShowGroup(): Set display state for group
  41. // SYNTAX: bool ShowGroup(string GroupName,int ShowCommand[,bool CommonGroupFlag])
  42. // WHERE: GroupName: Text name for the existing group
  43. //        CommonGroupFlag: False for personal group, else CommonGroup; default=False
  44. //        ShowCommand: One of the following values for display state
  45.       #define PMG_RESTORE         1 // Activates and displays the group window. If the window is minimized or maximized, Windows
  46.                                     // restores it to its original size and position.
  47.       #define PMG_SHOWMIN         2 // Activates the group window and displays it as an icon.
  48.       #define PMG_SHOWMAX         3 // Activates the group window and displays it as a maximized window.
  49.       #define PMG_SHOWNOACTIVATE  4 // Displays the group window in its most recent size and position. The window that is currently
  50.                                     // active remains active.
  51.       #define PMG_SHOWACTIVE      5 // Activates the group window and displays it in its current size and position.
  52.       #define PMG_SHOWMIN         6 // Minimizes the group window.
  53.       #define PMG_SHOWMINNOACTIVE 7 // Displays the group window as an icon. The currently active window remains active.
  54.       #define PMG_SHOWNA          8 // Displays the group window in its current state. The currently active window remains active.
  55. // RETURN: False on error, else success
  56. //
  57. //
  58. //**** Reload(): Remove and reload group
  59. // SYNTAX: bool Reload([string GroupName[,bool CommonGroupFlag]])
  60. // WHERE: GroupName: Text name for the existing group
  61. //        CommonGroupFlag: False for personal group, else CommonGroup; default=False
  62. // RETURN: False on error, else success
  63. // NOTE: You can use this command after making modification to update new group information
  64. //
  65. //
  66. //**** AddItem(): Add Program Item to existing group
  67. // SYNTAX: bool AddItem(string CmdLine[,string Name[,string IconPath[,int IconIndex[,int xPos,int yPos
  68. //                      [,string DefDir[,int HotKey[,bool fMinimize]]]]]]])
  69. // WHERE: CmdLine: Full Command Line to run application and optional parameters
  70. //        Name: The title below the icon
  71. //        IconPath: Filespec for the icon to display
  72. //        IconIndex: Index of icon in IconPathl; -1 for default
  73. //        xPos, yPos: Where to display icon in the group window; both -1 for default
  74. //        DefDir: Default directory
  75. //        HotKey: shortcut key to launch this item; 0 for no hotkey
  76. //                can OR key value with the following for combinations
  77.             #define HOT_SHIFT 0x100
  78.             #define HOT_CTRL  0x200
  79.             #define HOT_ALT   0x400
  80. //        fMinimize: boolean to minimize application window when launched
  81. // RETURN: False on error, else success
  82. // NOTE: Parameters that are not supplied or are NULL (strings) get default
  83. //
  84. //
  85. //**** DeleteItem(): Delete Program Item from existing group
  86. // SYNTAX: bool DeleteItem(string ItemName)
  87. // WHERE: ItemName: Text name for item to remove
  88. // RETURN: False on error, else success
  89. //
  90. //
  91. //**** ReplaceItem(): Delete Program Item and save position for AddItem()
  92. // SYNTAX: bool ReplaceItem(string ItemName)
  93. // WHERE: ItemName: Text name for item to remove
  94. // RETURN: False on error, else success
  95. //
  96. //
  97. //**** ExitProgman(): Terminate Program Manager
  98. // SYNTAX: bool ExitProgman(bool SaveGroups)
  99. // WHERE: SaveGroups: If True then save groups before closing
  100. // RETURN: False on error, else success
  101. //
  102. //
  103. //**** ProgmanGroups(): Query Program Manager for a list of all groups
  104. // SYNTAX: bool ProgmanGroups(string[] GroupList[,int GroupCount])
  105. // WHERE: GroupList: Returned array of GroupNames
  106. //        GroupCount: How many groups available (also 1 + GetArraySpan(GroupList))
  107. // MODIFIES: Modify GroupList and GroupCount
  108. // RETURN: False on error, else success
  109. //
  110. //
  111. //**** ProgmanGroupItems(): Enumerate items in group
  112. // SYNTAX: bool ProgmanGroupItems(string GroupName,struct GroupInfo[,struct[] ItemList])
  113. // WHERE: GroupName: Text name for the existing group
  114. //        GroupInfo: structure to receive data about this grouo, with members:
  115. //          .Name: string for name of this group
  116. //          .Path: string for group Path
  117. //          .Count: integer number of elements in this group
  118. //          .State: integer state as defined in ShowGroup()
  119. //        ItemList: If this parameter specified, then will receive an array of
  120. //                  information about each item in this group
  121. //                  (GroupInfo.Count elemenst), with these members
  122. //          .Description: string item text description
  123. //          .CommandLine: execution command string
  124. //          .WorkingDirectory: string path for item working directory
  125. //          .IconFile: string path for file conatining icon
  126. //          .IconID: integer Icon identifier in .IconFile
  127. //          .Col: integer column position of this item in group window
  128. //          .Row: integer row position of this item in group window
  129. //          .ShortcutKey: integer item shortcut execute key combination
  130. //          .RunMinized: bool False to run maximized, else minimized
  131. // MODIFIES: creates GroupInfo and (if supplied) ItemList
  132. // RETURN: False on error, else success
  133. //
  134. //
  135. //
  136.  
  137. #include <DDEcli.lib>
  138.  
  139. gProgmanConnectCount = 0;
  140. gProgmanDdeSession;
  141.  
  142. ConnectToProgman()
  143. {
  144.    if ( 0 == gProgmanConnectCount++ ) {
  145.       gProgmanDdeSession.Application = gProgmanDdeSession.Topic = "PROGMAN";
  146.       gProgmanDdeSession.TerminateFunction = "ProgmanHasDisconnected";
  147.       if ( !ConnectToServer(gProgmanDdeSession) )
  148.          gProgmanConnectCount = 0;
  149.    }
  150.    return( 0 != gProgmanConnectCount );
  151. }
  152.  
  153. ProgmanHasDisconnected(pddeSession)
  154. {
  155.    if ( gProgmanConnectCount ) {
  156.       printf("\aError. Program manager has disconnected");
  157.       abort();
  158.    }
  159. }
  160.  
  161. CloseProgmanConnection()
  162. {
  163.    if ( gProgmanConnectCount  &&  0 == --gProgmanConnectCount )
  164.       DisconnectFromServer(gProgmanDdeSession);
  165. }
  166.  
  167. IsProgmanRunning()
  168. {
  169.    lRunning = ConnectToProgman();
  170.    CloseProgmanConnection();
  171.    return lRunning;
  172. }
  173.  
  174. CreateGroup(pGroupName,pCommonGroupFlag)
  175. {
  176.    if ( 1 == va_arg() )
  177.       sprintf(lCmd,"[CreateGroup(\"%s\")]",pGroupName);
  178.    else
  179.       sprintf(lCmd,"[CreateGroup(\"%s\",%d)]",pGroupName,pCommonGroupFlag?1:0);
  180.    return ProgmanDdeExecute(lCmd);
  181. }
  182.  
  183. ShowGroup(pGroupName,pShowCommand,pCommonGroupFlag)
  184. {
  185.    if ( 2 == va_arg() )
  186.       sprintf(lCmd,"[ShowGroup(\"%s\",%d)]",pGroupName,pShowCommand);
  187.    else
  188.       sprintf(lCmd,"[CreateGroup(\"%s\",%d,%d)]",pGroupName,pShowCommand,pCommonGroupFlag?1:0);
  189.    return ProgmanDdeExecute(lCmd);
  190. }
  191.  
  192. DeleteGroup(pGroupName,pCommonGroupFlag)
  193. {
  194.    if ( 1 == va_arg() )
  195.       sprintf(lCmd,"[DeleteGroup(\"%s\")]",pGroupName);
  196.    else
  197.       sprintf(lCmd,"[DeleteGroup(\"%s\",%d)]",pGroupName,pCommonGroupFlag?1:0);
  198.    return ProgmanDdeExecute(lCmd);
  199. }
  200.  
  201. Reload(pGroupName,pCommonGroupFlag)
  202. {
  203.    strcpy(lCmd,"[Reload(");
  204.    if ( va_arg() && pGroupName )  sprintf(lCmd+strlen(lCmd),"\"%s\"",pGroupName);
  205.    if ( 1 < va_arg() )  sprintf(lCmd+strlen(lCmd),",%d",pCommonGroupFlag?1:0);
  206.    strcat(lCmd,")]");
  207.    return ProgmanDdeExecute(lCmd);
  208. }
  209.  
  210. AddItem(pCmdLine,pName,pIconPath,pIconIndex,pxPos,pyPos,pDefDir,pHotKey,pfMinimize)
  211. {
  212.    lArgC = va_arg();
  213.    sprintf(lCmd,"[AddItem(%s",pCmdLine);
  214.    if ( 1 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pName ? pName : "");
  215.    if ( 2 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pIconPath ? pIconPath : "");
  216.    if ( 3 < lArgC ) sprintf(lCmd+strlen(lCmd),-1 == pIconIndex ? "," : ",%d", pIconIndex);
  217.    if ( 4 < lArgC ) sprintf(lCmd+strlen(lCmd),",%d,%d",pxPos,pyPos);
  218.    if ( 6 < lArgC ) sprintf(lCmd+strlen(lCmd),",%s",pDefDir ? pDefDir : "");
  219.    if ( 7 < lArgC ) sprintf(lCmd+strlen(lCmd),",%d",pHotKey);
  220.    if ( 8 < lArgC ) strcat(lCmd,pfMinimize ? ",1" : ",0");
  221.    strcat(lCmd,")]");
  222.    return ProgmanDdeExecute(lCmd);
  223. }
  224.  
  225. DeleteItem(pItemName)
  226. {
  227.    sprintf(lCmd,"[DeleteItem(%s)]",pItemName);
  228.    return ProgmanDdeExecute(lCmd);
  229. }
  230.  
  231. ReplaceItem(pItemName)
  232. {
  233.    sprintf(lCmd,"[ReplaceItem(%s)]",pItemName);
  234.    return ProgmanDdeExecute(lCmd);
  235. }
  236.  
  237. ExitProgman(pbSaveGroups)
  238. {
  239.    sprintf( lCmd, "[ExitProgman(%d)]", pbSaveGroups ? 1 : 0 );
  240.    return ProgmanDdeExecute(lCmd);
  241. }
  242.  
  243. ProgmanDdeExecute(pExecuteCommandString)
  244. {
  245.    lSuccess = False;
  246.    if ( ConnectToProgman() ) {
  247.       if ( DdeExecute(gProgmanDdeSession,pExecuteCommandString) )
  248.          lSuccess = True;
  249.       CloseProgmanConnection();
  250.    }
  251.    return lSuccess;
  252. }
  253.  
  254. ProgmanGroups(pGroupList,pCount)
  255. {
  256.    bool lSuccess = False;
  257.    undefine(pGroupList);
  258.    if ( ConnectToProgman() ) {
  259.       if ( lData = RequestDataFromServer(gProgmanDdeSession,"Groups") ) {
  260.          for ( lCount = 0, lGroupName = strtok(lData,"\r\n");
  261.                NULL != lGroupName; lCount++, lGroupName = strtok(NULL,"\r\n") )
  262.             lSuccess = True, strcpy(pGroupList[lCount],lGroupName);
  263.       }
  264.       CloseProgmanConnection();
  265.    }
  266.    if ( 1 < va_arg() ) pCount = lCount;
  267.    return lSuccess;
  268. }
  269.  
  270. ProgmanGroupItems(pGroupName,pGroupInfo,pItemList)
  271. {
  272.    bool lSuccess = False;
  273.    undefine(pGroupInfo);
  274.    if ( ConnectToProgman() ) {
  275.       if ( lData = RequestDataFromServer(gProgmanDdeSession,pGroupName) ) {
  276.          // first line of data looks something like: "Main",C:\WIN\MAIN.GRP,9,4
  277.          if ( (lGroupStr = strtok(lData,"\r\n"))
  278.            && 4 == sscanf(lGroupStr,"%*c%[^\"]%*2c%[^,]%*c%d,%d",lG.Name,lG.Path,lG.Count,lG.State) ) {
  279.             pGroupInfo = lG;
  280.             lSuccess = True;
  281.             if ( 2 < va_arg() ) {
  282.                undefine(pItemList);
  283.                for ( lg.Count = 0; lItemStr = strtok(NULL,"\r\n"); ) {
  284.                   // each line like: "CEnvi","C:\CENVIW\CENVI.EXE",C:\CENVIW,C:\CENVIW\CENVI.EXE,174,0,0,0,0
  285.                   undefine(lI);
  286.                   lDescription = lItemStr + 1;
  287.                   if ( lItemStr = strstr(lItemStr+1,"\",\"") ) {
  288.                      lItemStr[0] = 0;
  289.                      lCommandLine = lItemStr + 3;
  290.                      if ( lItemStr = strstr(lItemStr+4,"\",") ) {
  291.                         lItemStr[0] = 0;
  292.                         lWorkingDirectory = lItemStr + 2;
  293.                         if ( lItemStr = strchr(lItemStr+2,',') ) {
  294.                            lItemStr[0] = 0;
  295.                            if ( 6 == sscanf(lItemStr+1,"%[^,]%*c%d,%d,%d,%d,%d",
  296.                                             lI.IconFile,lI.Col,lI.Row,lI.IconID,lI.ShortcutKey,lI.RunMinimized) ) {
  297.                               strcpy(lI.Description,lDescription);
  298.                               strcpy(lI.CommandLine,lCommandLine);
  299.                               strcpy(lI.WorkingDirectory,lWorkingDirectory);
  300.                               pItemList[lg.Count++] = lI;
  301.                            }
  302.                         }
  303.                      }
  304.                   }
  305.                }
  306.             }
  307.          }
  308.       }
  309.       CloseProgmanConnection();
  310.    }
  311.    return lSuccess;
  312. }
  313.  
  314.