home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / OpenDoc / ProcessMap / $Sources / CPInfo.cpp next >
Encoding:
C/C++ Source or Header  |  1995-04-28  |  1.5 KB  |  58 lines  |  [TEXT/MPCC]

  1. #ifndef _PROCESSMAP_
  2. #include "CPProcessMap.h"
  3. #endif
  4.  
  5. class CPInfo
  6. {
  7. private:
  8.     char* buffName;
  9.     FSSpec buffFSS;
  10.     ProcessInfoRec theInfo;
  11. public:
  12.      CPInfo(){buffName = new char[32];theInfo.processInfoLength=sizeof(ProcessInfoRec);theInfo.processName=(StringPtr)buffName;theInfo.processAppSpec=&buffFSS;};
  13.     ~CPInfo(){delete buffName;};
  14.  
  15.     OSErr GetPInfo(ProcessSerialNumber& thePSN);
  16.     void QueryInfo(CMyProcess& theProcess);
  17. };
  18.  
  19. OSErr CPInfo::GetPInfo(ProcessSerialNumber& thePSN)
  20. {
  21.     return ::GetProcessInformation(&thePSN, &theInfo);
  22. }
  23.  
  24. void CPInfo::QueryInfo(CMyProcess& theProcess)
  25. {
  26.     BlockMoveData(theInfo.processName, theProcess.pName, theInfo.processName[0]+1);
  27.     theProcess.lStartAddress = (long)theInfo.processLocation;
  28.     theProcess.lEndAddress   = theProcess.lStartAddress + theInfo.processSize;
  29.     theProcess.thePSN        = theInfo.processNumber;
  30. }
  31.  
  32. Boolean CPProcessMap::RefreshProcessMap(void)
  33. {
  34. ProcessSerialNumber thePSN;
  35. short sCount;
  36. Boolean fDirty=false;
  37.  
  38.     if ( ::TickCount() - lLastTick < 60 ) return fDirty;
  39.  
  40. CMyProcess theProcess;
  41. CPInfo theInfo;
  42.     lLastTick = ::TickCount();
  43.     sCount = 0;
  44.     thePSN.highLongOfPSN = 0;
  45.     thePSN.lowLongOfPSN  = kNoProcess;
  46.     while ( noErr == ::GetNextProcess(&thePSN) && sNumOfProcess < MAX_PROCESS )
  47.     {
  48.         if ( noErr == theInfo.GetPInfo(thePSN) )
  49.         {
  50.             theInfo.QueryInfo(theProcess);
  51.             if ( false == aProcesses[sCount].IsSameOne(theProcess) ){fDirty = true;aProcesses[sCount]=theProcess;}
  52.             sCount ++;
  53.         }
  54.     }
  55.     if ( sNumOfProcess != sCount ){fDirty=true;sNumOfProcess=sCount;}
  56.     return fDirty;
  57. }
  58.