home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ocl150a.zip / OCL / Samples / ProcStat / Source / ProcStat.cpp < prev    next >
C/C++ Source or Header  |  1997-01-27  |  4KB  |  210 lines

  1. // OCL Sample
  2. // Procstat.cpp
  3.  
  4.  
  5. #ifdef __BCPLUSPLUS__
  6.   #define __MSC
  7. #endif
  8.  
  9.  
  10. #define __OCL_RESOLVE_TEMPLATES__
  11. #include "..\Source\Procstat.hpp"
  12.  
  13. #if defined(__EMX__)
  14.   template class OContainer<MINIRECORDCORE, MINIRECORDCORE>;
  15. #endif
  16.  
  17. void main(void)
  18. {
  19.  Procstat sample;
  20.  
  21.  try
  22.   {        
  23.    sample.init(); 
  24.   }
  25.  
  26.  catch(OException &err)
  27.   {     
  28.    OMsgs msg;
  29.  
  30.    msg.error("Application Exception", err.description);
  31.    _exit(1);
  32.   }         
  33.  
  34.  OApp::current().run();
  35.  
  36.  _exit(0);
  37. }
  38.  
  39.  
  40. Procstat::Procstat()
  41.  : OFrame(PROCSTAT_MAIN) 
  42.  {}
  43.  
  44. Procstat::~Procstat()
  45. {
  46.  if (cnr) delete cnr; 
  47. }
  48.  
  49.  
  50. void Procstat::init()
  51. {
  52.  createFrame("OS/2 Processes");
  53.  
  54.  cnr = new PContainer(this);
  55.  cnr->createContainer();
  56.  cnr->setFont("8.Helv");
  57.  
  58.  showFrame();
  59. }
  60.  
  61.  
  62.  
  63. BOOL Procstat::OCommand(ULONG msg, MPARAM mp1, MPARAM mp2)
  64. {
  65.  switch(msg)
  66.   {
  67.    case WM_SIZE:
  68.      if (cnr)
  69.        WinSetWindowPos(cnr->hwnd, 0, 0, 0, 
  70.                        SHORT1FROMMP(mp2), SHORT2FROMMP(mp2), 
  71.                        SWP_SIZE);
  72.      break;
  73.  
  74.    case WM_COMMAND:
  75.      switch(SHORT1FROMMP(mp1))
  76.       {
  77.        case PROCSTAT_SETFONT: {
  78.         OString font(OFontDialog().getFont("Set Font", "Tree Font"));
  79.         if (font.getText())
  80.           cnr->setFont(font);
  81.         break; }
  82.  
  83.        case PROCSTAT_QUIT:
  84.         WinSendMsg(hwnd, WM_CLOSE, NULL, NULL);
  85.         break; 
  86.  
  87.        case PROCSTAT_REFRESH:
  88.         if (cnr) {
  89.          cnr->freeContainer();
  90.          cnr->setupItems(); }
  91.         break;
  92.       }
  93.      break;
  94.  
  95.    case WM_CLOSE:
  96.      OApp::current().forceQuit();
  97.      break;
  98.  
  99.    default:
  100.      return(OFrame::OCommand(msg, mp1, mp2));
  101.   }
  102.  return(TRUE);
  103. #ifdef __BCPLUSPLUS__
  104.   #pragma warn -par
  105. #endif
  106. }
  107. #ifdef __BCPLUSPLUS__
  108.   #pragma warn .par
  109. #endif
  110.  
  111.  
  112.  
  113. BOOL PContainer::setupItems()
  114. {
  115.  PMINIRECORDCORE  prec;
  116.  RECORDINSERT     ri;
  117.  
  118.  if (!getProcesses())         // OProcStat::getProcesses()
  119.    OThrowPM("OProcStat::getProcesses() failed", 0, OException::unrecoverable);
  120.  
  121.  
  122.  if ((prec = allocRecords(1)) == NULL)
  123.    return(FALSE);
  124.  
  125.  prec->cb = sizeof(MINIRECORDCORE);
  126.  prec->flRecordAttr = CRA_EXPANDED;
  127.  prec->pszIcon = "OS2KRNL";
  128.  prec->hptrIcon = hptr;
  129.  
  130.  memset(&ri, 0, sizeof(RECORDINSERT));
  131.  ri.cb                = sizeof(RECORDINSERT);
  132.  ri.pRecordOrder      = (PRECORDCORE) CMA_END;
  133.  ri.pRecordParent     = (PRECORDCORE) NULL;
  134.  ri.zOrder            = (USHORT) CMA_TOP;
  135.  ri.cRecordsInsert    = 1;
  136.  ri.fInvalidateRecord = FALSE;
  137.  
  138.  // insert them in one shot
  139.  insertRecord(prec, &ri);
  140.  
  141.  return((insertChilds(prec, 0)) &&   // insert childs of kernel
  142.         (insertChilds(prec, 1)) &&
  143.         (setCnrInfo(CMA_LINESPACING | CMA_CXTREEINDENT)) &&
  144.         (invalidateRecord()));
  145. }
  146.  
  147.  
  148. BOOL PContainer::insertChilds(PMINIRECORDCORE parentRecord, ULONG ulParent)
  149. {
  150.  PMINIRECORDCORE       prec;
  151.  RECORDINSERT          ri;
  152.  // we cannot use getFirst() because this member
  153.  // is recursive and must not change the list cursors
  154.  OListItem<OProcRecord> *cursor = ProcList.first();
  155.  
  156.  while(cursor)
  157.   {
  158.    if (cursor->item->PPid == ulParent)
  159.     {
  160.     if ((prec = allocRecords(1)) == NULL)
  161.       return(FALSE);
  162.  
  163.      prec->cb = sizeof(MINIRECORDCORE);
  164.      prec->flRecordAttr = CRA_EXPANDED;
  165.      prec->pszIcon = cursor->item->Module;
  166.      prec->hptrIcon = hptr;
  167.  
  168.      memset(&ri, 0, sizeof(RECORDINSERT));
  169.      ri.cb                = sizeof(RECORDINSERT);
  170.      ri.pRecordOrder      = (PRECORDCORE) CMA_END;
  171.      ri.pRecordParent     = (PRECORDCORE) parentRecord;
  172.      ri.zOrder            = (USHORT) CMA_TOP;
  173.      ri.cRecordsInsert    = 1;
  174.      ri.fInvalidateRecord = FALSE;
  175.     
  176.      if ((!insertRecord(prec, &ri)) ||
  177.          (!insertChilds(prec, cursor->item->Pid)))
  178.        return(FALSE);
  179.     }
  180.    cursor = cursor->next;
  181.   }
  182.  return(TRUE);
  183. }
  184.  
  185.  
  186.  
  187. PContainer::PContainer(pOFrame Parent)
  188.   : OContainer<MINIRECORDCORE, 
  189.                MINIRECORDCORE>(PROCSTAT_CNR, Parent,
  190.                CCS_AUTOPOSITION | CCS_MINIRECORDCORE,
  191.                CV_TREE | CA_TREELINE | CV_TEXT),
  192.     hptr(WinLoadPointer(HWND_DESKTOP, NULLHANDLE, PROCSTAT_MAIN))
  193. {
  194.  cnri.cyLineSpacing = 0;
  195.  cnri.cxTreeIndent = 15;
  196. }
  197.  
  198. PContainer::~PContainer() 
  199. {
  200.  freeContainer(); 
  201. }
  202.  
  203.  
  204. BOOL PContainer::setupDetails() 
  205. {
  206.  return(TRUE);
  207. }
  208.  
  209. // end of source
  210.