home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / WILDASS / SOURCE / PROGMGR.CPP < prev    next >
C/C++ Source or Header  |  1993-08-14  |  8KB  |  278 lines

  1. // progmgr.cpp : implementation file
  2. //
  3.  
  4. //#include "stdafx.h"
  5. //#include "morespac.h"
  6. #include <afxwin.h>
  7. #include <afxext.h> 
  8. #include <ctl3d.h>
  9.                       
  10. #include "resource.h"                      
  11. #include "progmgr.h"
  12. #include "grpfile.h"
  13.  
  14. #ifdef _DEBUG
  15. #undef THIS_FILE
  16. static char BASED_CODE THIS_FILE[] = __FILE__;
  17. #endif
  18.    
  19.    
  20.    
  21. /////////////////////////////////////////////////////////////////////////////
  22. // CProgMgrDlg dialog
  23.  
  24. CProgMgrDlg::CProgMgrDlg(CWnd* pParent /*=NULL*/)
  25.    : CDialog(CProgMgrDlg::IDD, pParent)
  26. {
  27.    //{{AFX_DATA_INIT(CProgMgrDlg)
  28.       // NOTE: the ClassWizard will add member initialization here
  29.    //}}AFX_DATA_INIT
  30. }
  31.  
  32. void CProgMgrDlg::DoDataExchange(CDataExchange* pDX)
  33. {
  34.    CDialog::DoDataExchange(pDX);
  35.    //{{AFX_DATA_MAP(CProgMgrDlg)
  36.    DDX_Control(pDX, IDC_LIST_APPS, m_lstItems);
  37.    DDX_Control(pDX, IDC_LIST_GROUPS, m_lstGroups);
  38.    //}}AFX_DATA_MAP
  39. }
  40.  
  41. BEGIN_MESSAGE_MAP(CProgMgrDlg, CDialog)
  42.    //{{AFX_MSG_MAP(CProgMgrDlg)
  43.    ON_LBN_SELCHANGE(IDC_LIST_GROUPS, OnSelchangeListGroups)
  44.    ON_LBN_DBLCLK(IDC_LIST_APPS, OnDblclkListApps)
  45.    ON_BN_CLICKED(IDC_HELP, OnClickedHelp)
  46.    //}}AFX_MSG_MAP
  47. END_MESSAGE_MAP()
  48.  
  49. /////////////////////////////////////////////////////////////////////////////
  50. // CProgMgrDlg message handlers
  51.  
  52. BOOL CProgMgrDlg::OnInitDialog()
  53. {
  54.    CDialog::OnInitDialog();
  55.    
  56.    // TODO: Add extra initialization here 
  57.    // CenterWindow();
  58.    
  59.    // find all group files
  60.    int iGroups=0;
  61.    while ( TRUE )
  62.    {  
  63.       iGroups++;
  64.       CString strGroup("Group");
  65.       char szBuf[10];
  66.       itoa( iGroups, szBuf, 10 );
  67.       strGroup+=szBuf;
  68.       char szReturnBuffer[255];         
  69.          
  70.       GetPrivateProfileString( "Groups", 
  71.          strGroup,
  72.          "none",
  73.          szReturnBuffer,
  74.          255,
  75.          "progman.ini" );      
  76.       
  77.       if ( CString( szReturnBuffer ) == CString("none") )                   
  78.          break;
  79.          
  80.       // ok, have a group file
  81.       ProgramMgrGroup * pGrp = new ProgramMgrGroup( szReturnBuffer );
  82.       
  83.       // store the pointer to the group file in the
  84.       // datat ptr section of the listbox
  85.       // and fill the boxes
  86.       int index = m_lstGroups.AddString( pGrp->Name() );   
  87.       m_lstGroups.SetItemDataPtr( index, (void*)pGrp );
  88.    }   
  89.    
  90.    // make the first group the selected one
  91.    m_lstGroups.SetCurSel( 0 );
  92.    
  93.    // display its items
  94.    OnSelchangeListGroups();   
  95.    
  96.    return TRUE;  // return TRUE  unless you set the focus to a control
  97. }
  98.                  
  99. #if 0                 
  100.   if ((fhGroupFile = OpenFile (lpszGroupFileName, &OpenBuff, OF_READ)) == NULL)
  101.     return FALSE;
  102.   
  103.   
  104.   // ******************************************************************
  105.   // Find out how much memory to allocate to hold the group file by
  106.   // seeking to the end of the file.  This gives us the number of 
  107.   // bytes that we have to allocate in the call to GlobalAlloc.
  108.   // ******************************************************************
  109.  
  110.   cbGroup = (WORD) _llseek (fhGroupFile, 0L, 2);
  111.   _llseek (fhGroupFile, 0L, 0);
  112.  
  113.   *ghMemGroupFileData = GlobalAlloc (GMEM_MOVEABLE, cbGroup);
  114.   lpGroupFileData = GlobalLock (*ghMemGroupFileData);
  115.   if (!lpGroupFileData)
  116.     {
  117.     _lclose (fhGroupFile);
  118.     return FALSE;
  119.     }
  120.  
  121.   if (!_lread (fhGroupFile, lpGroupFileData, cbGroup))
  122.     {
  123.     _lclose (fhGroupFile);
  124.  
  125.     if (GlobalUnlock (*ghMemGroupFileData))
  126.       GlobalFree (*ghMemGroupFileData);
  127.  
  128.     return FALSE;
  129.     }
  130.  
  131.   _lclose (fhGroupFile);
  132.   return TRUE;
  133. #endif
  134. #if 0
  135. // ----------------------------------------------
  136.   //**************************************************************
  137.   //  The rgiItems array in the group file may not have valid
  138.   //  information in it because it doesn't get updated fully
  139.   //  when the the user deletes an item from the group file.  That
  140.   //  is, the array doesn't get closed up to only include valid
  141.   //  offsets.  Instead, Windows puts 0 in the offset for the
  142.   //  deleted item.  So, what we're doing here is looking down the 
  143.   //  for non-zero entries in the array to get a true count (cItems)
  144.   //  of items in it.  In this way, we can use cItems as a limit in
  145.   //  the while loop below.
  146.   //**************************************************************
  147.  
  148.   _fmemcpy (&PMGroupHeader, lpGroupFileData, sizeof (PMGROUPHEADER));
  149.  
  150.   rgiItems = (WORD FAR *) &lpGroupFileData [sizeof (PMGROUPHEADER)];
  151.   i = cItems = 0;
  152.   while (i++ < PMGroupHeader.cItems)
  153.     {
  154.     if (*rgiItems)
  155.       cItems++;
  156.     rgiItems++;
  157.     }
  158.  
  159.   i = 0;
  160.   rgiItems = (WORD FAR *) &lpGroupFileData [sizeof (PMGROUPHEADER)];
  161.  
  162.   //  **************************************************************
  163.   //  Now that we have the count of valid items in the group file,
  164.   //  we cand go through and add the strings to the item list box.
  165.   //  **************************************************************
  166.   while (i < cItems)
  167.     {
  168.     if (*rgiItems)
  169.       {
  170.       i++;
  171.       // Get the item structure filled in
  172.       _fmemcpy (&PMItemData,
  173.                 &lpGroupFileData [*rgiItems],
  174.                 sizeof (PMITEMDATA));
  175.  
  176.       // Get the item name filled in
  177.       szTemp = szItemName;
  178.       do
  179.         *szTemp = lpGroupFileData [PMItemData.pName++];
  180.       while (*(szTemp++));
  181.  
  182.       //  Do the item command
  183.       szTemp = szCommand;
  184.       do
  185.         *szTemp = lpGroupFileData [PMItemData.pCommand++];
  186.       while (*(szTemp++));
  187.  
  188.       //  Fill in the icon path
  189.       szTemp = szIconPath;
  190.       do
  191.         *szTemp = lpGroupFileData [PMItemData.pIconPath++];
  192.       while (*(szTemp++));
  193.  
  194.       //  Add the information to the list box.
  195.  
  196.       wsprintf ((LPSTR) UserMsg, (LPSTR) "%.30s \t%.30s \t%.22s",
  197.                 (LPSTR) szItemName,
  198.                 (LPSTR) szIconPath,
  199.                 (LPSTR) szCommand);
  200.       SendMessage (hWndList, LB_ADDSTRING, 0, (LONG) (LPSTR) UserMsg);
  201.       }
  202.  
  203.     rgiItems++;
  204.     }
  205.  
  206. // ------------
  207.       while (i++ < PMGroupHeader->cItems)
  208.         {
  209.         if (*rgiItems)                // If there is an offset,
  210.           cItems++;                   // bump the count
  211.         rgiItems++;
  212.         }
  213.  
  214.       wsprintf ((LPSTR) szUserMsg, (LPSTR) "%.30s \t%.30s \t%d",
  215.                 (LPSTR) szFileName,
  216.                 (LPSTR) &lpGroupFileData [PMGroupHeader->pName],
  217.                 cItems);
  218.       SendMessage (hWndListBox, LB_ADDSTRING, 0, (LONG) (LPSTR) szUserMsg);
  219.       lpszGroupNames += lstrlen (lpszGroupNames) + 1;
  220.  
  221. #endif
  222.                  
  223. void CProgMgrDlg::OnSelchangeListGroups()
  224. {
  225.    // retrieve the program mgr group
  226.    int index = m_lstGroups.GetCurSel();
  227.    ASSERT( index!=LB_ERR );
  228.    
  229.    ProgramMgrGroup * pGrp = (ProgramMgrGroup *)m_lstGroups.GetItemDataPtr( index );
  230.    
  231.    // reset the item-listbox
  232.    m_lstItems.ResetContent();
  233.    
  234.    // fill it
  235.    for ( POSITION pos=pGrp->GetHeadPosition(); pos!=NULL; )
  236.    {
  237.       ProgramMgrItem * pItem = pGrp->GetNext( pos );
  238.       int index = m_lstItems.AddString( pItem->Name() );
  239.       m_lstItems.SetItemDataPtr( index, pItem );
  240.    }
  241.    
  242. }
  243.  
  244. void CProgMgrDlg::OnOK()
  245. {
  246.    // free the alloted memory
  247.    int nEntries = m_lstGroups.GetCount();
  248.    
  249.    for ( int iEntries = 0; iEntries < nEntries; iEntries++ )
  250.    {
  251.       ProgramMgrGroup * pGrp = (ProgramMgrGroup *)m_lstGroups.GetItemDataPtr( iEntries );
  252.       delete pGrp; 
  253.    }   
  254.    
  255.    CDialog::OnOK();
  256. }
  257.  
  258. void CProgMgrDlg::OnDblclkListApps()
  259. {
  260.    // Get the selecetd item
  261.    int index = m_lstItems.GetCurSel();
  262.    ASSERT( index != LB_ERR );
  263.    
  264.    // get the item
  265.    ProgramMgrItem * pItem = (ProgramMgrItem * )m_lstItems.GetItemDataPtr( index );
  266.    
  267.    // run the command
  268.    WinExec( pItem->Path(), SW_SHOWNORMAL );
  269.    
  270.    // fade ....
  271.    OnOK();
  272. }
  273.  
  274. void CProgMgrDlg::OnClickedHelp()
  275. {
  276.       AfxGetApp()->WinHelp( 0L, HELP_CONTENTS );
  277. }
  278.