Click here to Skip to main content
15,893,904 members
Articles / Desktop Programming / WTL

A little tool to show some system informations

Rate me:
Please Sign up or sign in to vote.
4.59/5 (15 votes)
12 May 2007CPOL1 min read 40.1K   3K   42  
This small tool shows some real-time system information, such as network speed, CPU utilization, time period and so on on the screen .
#pragma once

#include "resource.h"
#include <vector>
#include "ChartMan.h"


using namespace std;


extern CAppModule _Module;

class CHistoryDlg : public CDialogImpl<CHistoryDlg>,
	public CWinDataExchange<CHistoryDlg>
{
public:
	enum { IDD = IDD_DIALOG_HISTORY };

	BEGIN_MSG_MAP(CHistoryDlg)
		MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
		COMMAND_ID_HANDLER(IDOK, OnCloseCmd)
		COMMAND_ID_HANDLER(IDCANCEL, OnCloseCmd)
		MSG_WM_TIMER(OnTimer)
		NOTIFY_HANDLER(IDC_TAB_CHART, TCN_SELCHANGE, OnTabSelChange)
//		REFLECT_NOTIFICATIONS ()
	END_MSG_MAP()

	BEGIN_DDX_MAP(COptionDlg)

	END_DDX_MAP()

public:
	CHistoryDlg()
	{
		nCurSel = 0;
	}

	~CHistoryDlg()
	{
		Clear();
	}

	void InitRenderMan(vector<CStrSegment *> & v)
	{
		vector<CStrSegment *>::const_iterator it = v.begin();
		CStrSegment * pss;

		Clear();
		for(; it != v.end(); it++)
		{
			pss = *it;
			CChartMan * pcm;
			switch(pss->GetType())
			{
				case sstUpSpeed:
				case sstDownSpeed:
				case sstPhisicalMemory:
				case sstCPU:
					pcm = new CChartMan;
					pcm->SetSource(pss);
					vCharts.push_back(pcm);
					break;
				default:
					break;
			}
		}
	}

	void SetCurSel(int n){nCurSel = n;}
	int GetCurSel(void){return nCurSel;}
protected:
	CTabCtrl tcTabs;
	vector<CChartMan *> vCharts;
	int nCurSel;


	void Clear(void)
	{
		vector<CChartMan *>::const_iterator it;
		for(it = vCharts.begin(); it != vCharts.end(); it++)
			delete (*it);
		vCharts.clear();
	}

	// Handler prototypes (uncomment arguments if needed):
	//	LRESULT MessageHandler(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	//	LRESULT CommandHandler(WORD /*wNotifyCode*/, WORD /*wID*/, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	//	LRESULT NotifyHandler(int /*idCtrl*/, LPNMHDR /*pnmh*/, BOOL& /*bHandled*/)

	LRESULT OnInitDialog(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/)
	{
		tcTabs.Attach(GetDlgItem(IDC_TAB_CHART));

		vector<CChartMan *>::const_iterator it;
		for(it = vCharts.begin(); it != vCharts.end(); it++)
		{
			tcTabs.AddItem((*it)->GetSource()->GetDesc());
		}

		this->DoDataExchange();

		CenterWindow(GetParent());

		CRect r;

		tcTabs.GetWindowRect(&r);
		tcTabs.AdjustRect(FALSE, &r);
		tcTabs.ScreenToClient(&r);

		r.DeflateRect(8, 8, 8, 8);
		for(it = vCharts.begin(); it != vCharts.end(); it++)
		{
			(*it)->SetTarget(tcTabs);
			(*it)->SetDisplayRect(r);
		}

		if(nCurSel >= 0 && nCurSel < tcTabs.GetItemCount())
		{
			tcTabs.SetCurSel(nCurSel);
		}
		else
			nCurSel = 0;

		SetTimer(1, 500);
/*
		CString str;
		int n = tcTabs.GetCurSel();
		str.Format(_T("%d"), n);
		MessageBox(str);
*/
		return TRUE;
	}

	LRESULT OnCloseCmd(WORD /*wNotifyCode*/, WORD wID, HWND /*hWndCtl*/, BOOL& /*bHandled*/)
	{
		KillTimer(1);

		nCurSel = tcTabs.GetCurSel();
		EndDialog(wID);
		return 0;
	}

	void OnTimer(UINT)
	{
		int n = tcTabs.GetCurSel();
		if(n >= 0)
		{
			vCharts[n]->Render();
		}
	}

	LRESULT OnTabSelChange(int, LPNMHDR, BOOL &)
	{
/*
		CString str;

		int n = tcTabs.GetCurSel();
		str.Format(_T("Current selected: %d"), n);

		MessageBox(str);
*/
		return 0;
	}
};

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
China China
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions