home *** CD-ROM | disk | FTP | other *** search
/ Netscape Plug-Ins Developer's Kit / Netscape_Plug-Ins_Developers_Kit.iso / source / Chap09 / NPTREE / NPWINDOW.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-21  |  4.2 KB  |  200 lines

  1.  
  2. //
  3. // npwindow.cpp
  4. //
  5.  
  6. #include "..\inc\stdafx.h"
  7. #include "nptree.h"
  8. #include "npwindow.h"
  9.  
  10.  
  11. //
  12. // Constructor
  13. //
  14. CPluginWindow::CPluginWindow (CCpuMon *pCpuMon)
  15. {
  16.     ::MessageBox(NULL, "PluginWindow Constructor","Inside PluginWindow Constructor",MB_OK);
  17.   
  18.     this->pCpuMon = pCpuMon;
  19.  
  20.     memset (&vmstat, 0, sizeof(VMSTAT));
  21. }
  22.  
  23.  
  24. //
  25. // Destructor
  26. //
  27. CPluginWindow::~CPluginWindow()
  28. {
  29. }
  30.  
  31.  
  32. //
  33. // InitWindow - Create the button
  34. //
  35. void CPluginWindow::InitWindow() 
  36. {
  37.     /*
  38.     CRect rect(30,70,110,110);
  39.     cbUpdate = new CButton();
  40.     cbUpdate->Create("Update", BS_PUSHBUTTON | WS_VISIBLE, rect, this, ID_UPDATE_CHART);
  41. */
  42.     ::MessageBox(NULL, "InitWindow","Inside InitWindow",MB_OK);
  43.   
  44.     InitCommonControls();
  45.     RECT rcClient;
  46.     GetClientRect(&rcClient);
  47.     rcClient.top = rcClient.left = 0;
  48.     
  49.     ::MessageBox(NULL, "About to call Create","Inside InitWindow",MB_OK);
  50.   
  51.     m_Tree.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |
  52.         TVS_HASLINES | TVS_HASBUTTONS |
  53.         TVS_LINESATROOT,
  54.         rcClient,
  55.         this, ID_TREE);
  56.     ::MessageBox(NULL, "Done with Create","Inside InitWindow",MB_OK);
  57.   
  58.   }
  59.  
  60.  
  61. //
  62. // CleanupWindow - Delete the button
  63. //
  64. void CPluginWindow::CleanupWindow ()
  65. {
  66.     //delete cbUpdate;
  67. }
  68.  
  69.  
  70. //
  71. // UpdateChart - Parse out the vmstat data 
  72. //
  73. /*
  74. BOOL CPluginWindow::UpdateChart (FILE* fp) 
  75. {
  76.     MessageBeep (0xFFFFFFFF);
  77.  
  78.     // Read five lines from the file
  79.  
  80.     for (int i=0; i<5; i++)
  81.     {
  82.         // First line should contain the VMSTAT signiture
  83.  
  84.         if (fgets (FileLine, sizeof(FileLine), fp))
  85.         {
  86.             if (i == 0)
  87.                 if (strncmp(FileLine, "VMSTAT", sizeof("VMSTAT")-1))
  88.                     return FALSE;
  89.         }
  90.     }
  91.  
  92.     // Parse out the vmstat data
  93.  
  94.     sscanf (FileLine, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
  95.         &vmstat.r, &vmstat.b, &vmstat.w,    // Threads 
  96.         &vmstat.avm, &vmstat.fre,    // Memory
  97.         &vmstat.re, &vmstat.at, &vmstat.pi, &vmstat.po, &vmstat.fr, &vmstat.de,    // Pages 
  98.         &vmstat.sr, &vmstat.d0, &vmstat.s1, &vmstat.s2, &vmstat.s3,    // More Pages
  99.         &vmstat.interrupts, &vmstat.syscalls, &vmstat.contextswitch,    // Faults
  100.         &vmstat.user, &vmstat.system, &vmstat.idle);    // CPU
  101.  
  102.     // Make the numbers bigger
  103.  
  104.     vmstat.user *= 4;
  105.     vmstat.system *= 4;
  106.     vmstat.idle *= 4;
  107.  
  108.     CDC* dc = GetDC ();
  109.  
  110.     DrawRects (dc);
  111.  
  112.     ReleaseDC (dc);
  113.  
  114.     return TRUE;
  115. }
  116.  
  117.  
  118. //
  119. // DrawRects - Draw the CPU Monitor bar graph and color keys
  120. //
  121. void CPluginWindow::DrawRects(CDC* dc) 
  122. {
  123.     // Draw the bar graph
  124.  
  125.     CBrush br(RGB(0xFF,0,0));
  126.     dc->SelectObject (br);
  127.     dc->Rectangle (10, 10, vmstat.user+10, 60);
  128.  
  129.     CBrush br2(RGB(0,0xFF,0));
  130.     dc->SelectObject (br2);
  131.     dc->Rectangle (vmstat.user+10, 10, vmstat.user+vmstat.system+10, 60);
  132.  
  133.     CBrush br3(RGB(0,0,0xFF));
  134.     dc->SelectObject (br3);
  135.     dc->Rectangle (vmstat.user+vmstat.system+10, 10, vmstat.user+vmstat.system+vmstat.idle+10, 60);
  136.  
  137.     // Draw the color keys
  138.  
  139.     CRect rect(120,70,200,110);
  140.     dc->SelectObject (br);
  141.     dc->Rectangle (&rect);
  142.     dc->SetBkColor (RGB(0xFF,0,0));
  143.     dc->DrawText ("User", strlen("User"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  144.  
  145.     rect.SetRect(210,70,290,110);
  146.     dc->SelectObject (br2);
  147.     dc->Rectangle (&rect);
  148.     dc->SetBkColor (RGB(0,0xFF,0));
  149.     dc->DrawText ("System", strlen("System"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  150.  
  151.     rect.SetRect(300,70,380,110);
  152.     dc->SelectObject (br3);
  153.     dc->Rectangle (&rect);
  154.     dc->SetBkColor (RGB(0,0,0xFF));
  155.     dc->DrawText ("Idle", strlen("Idle"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
  156. }
  157.  
  158. */
  159. //
  160. // OnUpdate - The "Update" button was clicked
  161. //
  162. /*void CPluginWindow::OnUpdate() 
  163. {
  164.     if (pCpuMon)
  165.         if (!pCpuMon->RequestUpdate ())
  166.             AfxMessageBox ("Can't update now !");
  167. }
  168. */
  169.  
  170. //
  171. // OnPaint - Redraw bar graph 
  172. //
  173. void CPluginWindow::OnPaint() 
  174.     CPaintDC DC(this);
  175.     TV_ITEM tvi;
  176.     char str1[40];
  177.     char str2[255];
  178.  
  179.     tvi.hItem = hTreeCurrent;
  180.     tvi.pszText = str1;
  181.     tvi.cchTextMax = sizeof(str1) - 1;
  182.     tvi.mask = TVIF_TEXT | TVIF_HANDLE;
  183.     m_Tree.GetItem(&tvi);
  184.     wsprintf(str2, "Current selection: %s", tvi.pszText);
  185.     DC.TextOut(2, 150, str2, strlen(str2));
  186.  
  187. //    DrawRects (&dc);
  188. }
  189.  
  190.  
  191.  
  192.  
  193. BEGIN_MESSAGE_MAP( CPluginWindow, CWnd )
  194.     //{{AFX_MSG_MAP( CMainWindow )
  195.     ON_WM_PAINT ()
  196.     //}}AFX_MSG_MAP
  197. END_MESSAGE_MAP()
  198.  
  199.