home *** CD-ROM | disk | FTP | other *** search
-
- //
- // npwindow.cpp
- //
-
- #include "..\inc\stdafx.h"
- #include "nptree.h"
- #include "npwindow.h"
-
-
- //
- // Constructor
- //
- CPluginWindow::CPluginWindow (CCpuMon *pCpuMon)
- {
- ::MessageBox(NULL, "PluginWindow Constructor","Inside PluginWindow Constructor",MB_OK);
-
- this->pCpuMon = pCpuMon;
-
- memset (&vmstat, 0, sizeof(VMSTAT));
- }
-
-
- //
- // Destructor
- //
- CPluginWindow::~CPluginWindow()
- {
- }
-
-
- //
- // InitWindow - Create the button
- //
- void CPluginWindow::InitWindow()
- {
- /*
- CRect rect(30,70,110,110);
- cbUpdate = new CButton();
- cbUpdate->Create("Update", BS_PUSHBUTTON | WS_VISIBLE, rect, this, ID_UPDATE_CHART);
- */
- ::MessageBox(NULL, "InitWindow","Inside InitWindow",MB_OK);
-
- InitCommonControls();
- RECT rcClient;
- GetClientRect(&rcClient);
- rcClient.top = rcClient.left = 0;
-
- ::MessageBox(NULL, "About to call Create","Inside InitWindow",MB_OK);
-
- m_Tree.Create(WS_VISIBLE | WS_CHILD | WS_BORDER |
- TVS_HASLINES | TVS_HASBUTTONS |
- TVS_LINESATROOT,
- rcClient,
- this, ID_TREE);
- ::MessageBox(NULL, "Done with Create","Inside InitWindow",MB_OK);
-
- }
-
-
- //
- // CleanupWindow - Delete the button
- //
- void CPluginWindow::CleanupWindow ()
- {
- //delete cbUpdate;
- }
-
-
- //
- // UpdateChart - Parse out the vmstat data
- //
- /*
- BOOL CPluginWindow::UpdateChart (FILE* fp)
- {
- MessageBeep (0xFFFFFFFF);
-
- // Read five lines from the file
-
- for (int i=0; i<5; i++)
- {
- // First line should contain the VMSTAT signiture
-
- if (fgets (FileLine, sizeof(FileLine), fp))
- {
- if (i == 0)
- if (strncmp(FileLine, "VMSTAT", sizeof("VMSTAT")-1))
- return FALSE;
- }
- }
-
- // Parse out the vmstat data
-
- sscanf (FileLine, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d",
- &vmstat.r, &vmstat.b, &vmstat.w, // Threads
- &vmstat.avm, &vmstat.fre, // Memory
- &vmstat.re, &vmstat.at, &vmstat.pi, &vmstat.po, &vmstat.fr, &vmstat.de, // Pages
- &vmstat.sr, &vmstat.d0, &vmstat.s1, &vmstat.s2, &vmstat.s3, // More Pages
- &vmstat.interrupts, &vmstat.syscalls, &vmstat.contextswitch, // Faults
- &vmstat.user, &vmstat.system, &vmstat.idle); // CPU
-
- // Make the numbers bigger
-
- vmstat.user *= 4;
- vmstat.system *= 4;
- vmstat.idle *= 4;
-
- CDC* dc = GetDC ();
-
- DrawRects (dc);
-
- ReleaseDC (dc);
-
- return TRUE;
- }
-
-
- //
- // DrawRects - Draw the CPU Monitor bar graph and color keys
- //
- void CPluginWindow::DrawRects(CDC* dc)
- {
- // Draw the bar graph
-
- CBrush br(RGB(0xFF,0,0));
- dc->SelectObject (br);
- dc->Rectangle (10, 10, vmstat.user+10, 60);
-
- CBrush br2(RGB(0,0xFF,0));
- dc->SelectObject (br2);
- dc->Rectangle (vmstat.user+10, 10, vmstat.user+vmstat.system+10, 60);
-
- CBrush br3(RGB(0,0,0xFF));
- dc->SelectObject (br3);
- dc->Rectangle (vmstat.user+vmstat.system+10, 10, vmstat.user+vmstat.system+vmstat.idle+10, 60);
-
- // Draw the color keys
-
- CRect rect(120,70,200,110);
- dc->SelectObject (br);
- dc->Rectangle (&rect);
- dc->SetBkColor (RGB(0xFF,0,0));
- dc->DrawText ("User", strlen("User"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- rect.SetRect(210,70,290,110);
- dc->SelectObject (br2);
- dc->Rectangle (&rect);
- dc->SetBkColor (RGB(0,0xFF,0));
- dc->DrawText ("System", strlen("System"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
-
- rect.SetRect(300,70,380,110);
- dc->SelectObject (br3);
- dc->Rectangle (&rect);
- dc->SetBkColor (RGB(0,0,0xFF));
- dc->DrawText ("Idle", strlen("Idle"), &rect, DT_CENTER | DT_VCENTER | DT_SINGLELINE);
- }
-
- */
- //
- // OnUpdate - The "Update" button was clicked
- //
- /*void CPluginWindow::OnUpdate()
- {
- if (pCpuMon)
- if (!pCpuMon->RequestUpdate ())
- AfxMessageBox ("Can't update now !");
- }
- */
-
- //
- // OnPaint - Redraw bar graph
- //
- void CPluginWindow::OnPaint()
- {
- CPaintDC DC(this);
- TV_ITEM tvi;
- char str1[40];
- char str2[255];
-
- tvi.hItem = hTreeCurrent;
- tvi.pszText = str1;
- tvi.cchTextMax = sizeof(str1) - 1;
- tvi.mask = TVIF_TEXT | TVIF_HANDLE;
- m_Tree.GetItem(&tvi);
- wsprintf(str2, "Current selection: %s", tvi.pszText);
- DC.TextOut(2, 150, str2, strlen(str2));
-
- // DrawRects (&dc);
- }
-
-
-
-
- BEGIN_MESSAGE_MAP( CPluginWindow, CWnd )
- //{{AFX_MSG_MAP( CMainWindow )
- ON_WM_PAINT ()
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
-
-