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

  1. // CmmGroup.cmm - CEnvi sample file to demonstrate using DDE.lib,
  2. // ver.1          DDEcli.lib and Progman.lib to create and fill a group
  3.  
  4. #include <ProgMan.lib>
  5. #include <MsgBox.lib>
  6.  
  7. GroupName = "CEnvi Samples";
  8.  
  9. main(argc,argv)
  10. {
  11.    CmmPath = GetFilePath(argv[0]);
  12.    sprintf(msg,"CmmGroup will create a Program Manager group\n"
  13.                "called \"%s\" containing all of the\n"
  14.                "*.cmm files in directory:\n"
  15.                "    %s\n\nCreate Group?",GroupName,CmmPath);
  16.    if ( IDYES == MessageBox(msg,"Create CEnvi Samples Group?",MB_YESNO) ) {
  17.  
  18.       // check if program manager is already running.  If not then start it
  19.       if ( SpawnProgman = !IsProgmanRunning() ) {
  20.          // program manager is not executing, and so start it
  21.          if ( 0 == spawn(P_NOWAIT,"Progman.exe") ) {
  22.             ErrorMessage("Program Manager could not be started.");
  23.             exit(EXIT_FAILURE);
  24.          }
  25.       }
  26.  
  27.       // connect to program manager and continue
  28.       ConnectToProgman();
  29.  
  30.       AddCEnviGroup(CmmPath);
  31.  
  32.       // work is done, so disconnect
  33.       CloseProgmanConnection();
  34.  
  35.       // If program manager was manually started, then tell it to close
  36.       if ( SpawnProgman )
  37.          printf("ExitProgman returns %d\n",ExitProgman(True)),getch();
  38.    }
  39.    return(EXIT_SUCCESS);
  40. }
  41.  
  42. AddCEnviGroup(path)  // add group with all the .cmm files in this path
  43. {
  44.    // determine that group does not already exist
  45.    if ( ProgmanGroupItems(GroupName,GInfo) ) {
  46.       ErrorMessage("Group \"%s\" already exists.\nCannot create group.",GroupName);
  47.       return;
  48.    }
  49.  
  50.    // convert path to a full path name, with *.cmm file extension for the search
  51.    sprintf(SearchSpec,"%s\\*.cmm",FullPath(path));
  52.  
  53.    // search the path directory for all *.cmm files
  54.    if ( !(FileList = Directory(SearchSpec)) ) {
  55.       ErrorMessage("No *.CMM files found");
  56.       return;
  57.    }
  58.  
  59.    // create the CEnvi group and make sure it is active
  60.    assert( CreateGroup(GroupName) );
  61.    assert( ShowGroup(GroupName,PMG_SHOWACTIVE) );
  62.  
  63.    // want full spec for the path
  64.    strcpy(FullPathSpec,SplitFileName(SearchSpec).dir);
  65.  
  66.    // For the icon, will use CEnvi's icon, so need full path of CEnvi
  67.    CEnviFullSpec = GetMyExeSpec();
  68.  
  69.    // for each file in FileList, add an entry in the group
  70.    for ( i = 0; i <= GetArraySpan(FileList); i++ ) {
  71.       filespec = FileList[i].name;
  72.       // Title will be name without the extension, first letter uppercase then all lower
  73.       strcpy(Title,SplitFileName(filespec).name);
  74.       strlwr(Title);
  75.       Title[0] = toupper(Title[0]);
  76.       AddItem(filespec,Title, // .CMM is associated, and so just add that file
  77.               CEnviFullSpec,0,  // use the CEnvi.exe icon
  78.               -1,-1,          // accept default position
  79.               FullPathSpec);  // default directory
  80.    }
  81. }
  82.  
  83. GetFilePath(PartialSpec)   // return full directory path for this spec, without final '\'
  84. {
  85.    dir = SplitFileName(FullPath(PartialSpec)).dir;
  86.    dir[strlen(dir)-1] = 0;
  87.    return dir;
  88. }
  89.  
  90. GetMyExeSpec() // return full path for current CEnvi instance
  91. {
  92.    ExeName[0] = ExeName[400] = '\0';
  93.    DynamicLink("KERNEL","GETMODULEFILENAME",SWORD16,PASCAL,
  94.                Instance(),ExeName,399);
  95.    return ExeName;
  96. }
  97.  
  98. ErrorMessage(FormatString/*,arg,arg,arg*/) // display printf-like error message
  99. {
  100.    va_start(va_list,FormatString);
  101.    vsprintf(msg,FormatString,va_list);
  102.    MessageBox(msg,"ERROR!",MB_ICONEXCLAMATION);
  103.    va_end(va_list);
  104. }
  105.