📄 statisticsdlg.cpp
字号:
//this file is part of eMule
//Copyright (C)2002 Merkur ( devs@emule-project.net / http://www.emule-project.net )
//
//This program is free software; you can redistribute it and/or
//modify it under the terms of the GNU General Public License
//as published by the Free Software Foundation; either
//version 2 of the License, or (at your option) any later version.
//
//This program is distributed in the hope that it will be useful,
//but WITHOUT ANY WARRANTY; without even the implied warranty of
//MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//GNU General Public License for more details.
//
//You should have received a copy of the GNU General Public License
//along with this program; if not, write to the Free Software
//Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include "stdafx.h"
#include "emule.h"
#include "StatisticsDlg.h"
#include "UploadQueue.h"
#include "Statistics.h"
#include "emuledlg.h"
#include "OtherFunctions.h"
#include "WebServer.h"
#include "DownloadQueue.h"
#include "ClientList.h"
#include "Preferences.h"
#include "ListenSocket.h"
#include "ServerList.h"
#include "SharedFileList.h"
#include "UpDownClient.h"
#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
extern _CRT_ALLOC_HOOK g_pfnPrevCrtAllocHook;
#endif
// CStatisticsDlg dialog
IMPLEMENT_DYNAMIC(CStatisticsDlg, CDialog)
CStatisticsDlg::CStatisticsDlg(CWnd* pParent /*=NULL*/)
: CResizableDialog(CStatisticsDlg::IDD, pParent) , m_DownloadOMeter( 3 ),m_Statistics(4),m_UploadOMeter(5)
{
m_oldcx=0;
m_oldcy=0;
}
CStatisticsDlg::~CStatisticsDlg()
{
#ifdef _DEBUG
POSITION pos = blockFiles.GetStartPosition();
while (pos != NULL)
{
const unsigned char* fileName;
HTREEITEM* pTag;
blockFiles.GetNextAssoc(pos, fileName, pTag);
delete pTag;
}
#endif
}
void CStatisticsDlg::DoDataExchange(CDataExchange* pDX)
{
CResizableDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CExoSliderDlg)
DDX_Control(pDX, IDC_STATTREE, stattree);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStatisticsDlg, CResizableDialog)
//{{AFX_MSG_MAP(CStatisticsDlg)
ON_WM_SHOWWINDOW()
ON_WM_SIZE()
//}}AFX_MSG_MAP
ON_BN_CLICKED(IDC_BNMENU, OnMenuButtonClicked)
ON_WM_SYSCOLORCHANGE()
END_MESSAGE_MAP()
void CStatisticsDlg::OnSysColorChange()
{
CResizableDialog::OnSysColorChange();
SetAllIcons();
}
void CStatisticsDlg::SetAllIcons()
{
InitWindowStyles(this);
CImageList iml;
iml.Create(16, 16, theApp.m_iDfltImageListColorFlags | ILC_MASK, 0, 1);
iml.Add(CTempIconLoader(_T("StatsGeneric"))); // Dots & Arrow (Default icon for stats)
iml.Add(CTempIconLoader(_T("Up1Down1"))); // Transfer
iml.Add(CTempIconLoader(_T("Pref_Connection"))); // Connection
iml.Add(CTempIconLoader(_T("StatsClients"))); // Clients
iml.Add(CTempIconLoader(_T("Pref_Server"))); // Server
iml.Add(CTempIconLoader(_T("SharedFiles"))); // Shared Files
iml.Add(CTempIconLoader(_T("Upload"))); // Transfer > Upload
iml.Add(CTempIconLoader(_T("Download"))); // Transfer > Download
iml.Add(CTempIconLoader(_T("Statistics"))); // Session Sections
iml.Add(CTempIconLoader(_T("StatsCumulative"))); // Cumulative Sections
iml.Add(CTempIconLoader(_T("Pref_Tweak"))); // Records
iml.Add(CTempIconLoader(_T("ConnectedHighHigh"))); // Connection > General
iml.Add(CTempIconLoader(_T("Pref_Scheduler"))); // Time Section
iml.Add(CTempIconLoader(_T("Pref_Statistics"))); // Time > Averages and Projections
iml.Add(CTempIconLoader(_T("StatsDay"))); // Time > Averages and Projections > Daily
iml.Add(CTempIconLoader(_T("StatsMonth"))); // Time > Averages and Projections > Monthly
iml.Add(CTempIconLoader(_T("StatsYear"))); // Time > Averages and Projections > Yearly
iml.Add(CTempIconLoader(_T("HardDisk"))); // Diskspace
stattree.SetImageList(&iml, TVSIL_NORMAL);
imagelistStatTree.DeleteImageList();
imagelistStatTree.Attach(iml.Detach());
COLORREF crBk = GetSysColor(COLOR_WINDOW);
COLORREF crFg = GetSysColor(COLOR_WINDOWTEXT);
LPCTSTR pszSkinProfile = thePrefs.GetSkinProfile();
if (pszSkinProfile != NULL && pszSkinProfile[0] != _T('\0'))
{
TCHAR szColor[MAX_PATH];
GetPrivateProfileString(_T("Colors"), _T("StatisticsTvBk"), _T(""), szColor, ARRSIZE(szColor), pszSkinProfile);
if (szColor[0] == _T('\0'))
GetPrivateProfileString(_T("Colors"), _T("DefLvBk"), _T(""), szColor, ARRSIZE(szColor), pszSkinProfile);
if (szColor[0] != _T('\0'))
{
UINT red, grn, blu;
int iVals = _stscanf(szColor, _T("%i , %i , %i"), &red, &grn, &blu);
if (iVals == 3)
crBk = RGB(red, grn, blu);
}
GetPrivateProfileString(_T("Colors"), _T("StatisticsTvFg"), _T(""), szColor, ARRSIZE(szColor), pszSkinProfile);
if (szColor[0] == _T('\0'))
GetPrivateProfileString(_T("Colors"), _T("DefLvFg"), _T(""), szColor, ARRSIZE(szColor), pszSkinProfile);
if (szColor[0] != _T('\0'))
{
UINT red, grn, blu;
int iVals = _stscanf(szColor, _T("%i , %i , %i"), &red, &grn, &blu);
if (iVals == 3)
crFg = RGB(red, grn, blu);
}
}
stattree.SetBkColor(crBk);
stattree.SetTextColor(crFg);
}
BOOL CStatisticsDlg::OnInitDialog()
{
CResizableDialog::OnInitDialog();
EnableWindow(FALSE);
SetAllIcons();
if (theApp.emuledlg->m_fontMarlett.m_hObject)
{
GetDlgItem(IDC_BNMENU)->SetFont(&theApp.emuledlg->m_fontMarlett);
GetDlgItem(IDC_BNMENU)->SetWindowText(_T("6")); // show a down-arrow
}
CreateMyTree();
#ifdef _DEBUG
if (g_pfnPrevCrtAllocHook)
{
h_debug = stattree.InsertItem( _T("Debug info") );stattree.SetItemData(h_debug,0);
h_blocks = stattree.InsertItem(_T("Blocks"),h_debug);stattree.SetItemData(h_blocks,1);
debug1 = stattree.InsertItem(_T("Free"),h_blocks);stattree.SetItemData(debug1,1);
debug2 = stattree.InsertItem(_T("Normal"),h_blocks);stattree.SetItemData(debug2,1);
debug3 = stattree.InsertItem(_T("CRT"),h_blocks);stattree.SetItemData(debug3,1);
debug4 = stattree.InsertItem(_T("Ignore"),h_blocks);stattree.SetItemData(debug4,1);
debug5 = stattree.InsertItem(_T("Client"),h_blocks);stattree.SetItemData(debug5,1);
stattree.Expand(h_debug,TVE_EXPAND);
stattree.Expand(h_blocks,TVE_EXPAND);
}
#endif
// Setup download-scope
CRect rect;
GetDlgItem(IDC_SCOPE_D)->GetWindowRect(rect) ;
ScreenToClient(rect) ;
m_DownloadOMeter.Create(WS_VISIBLE | WS_CHILD, rect, this) ;
SetARange(true,thePrefs.GetMaxGraphDownloadRate());
m_DownloadOMeter.SetYUnits(GetResString(IDS_KBYTESEC)) ;
// Setup upload-scope
GetDlgItem(IDC_SCOPE_U)->GetWindowRect(rect) ;
ScreenToClient(rect) ;
m_UploadOMeter.Create(WS_VISIBLE | WS_CHILD, rect, this) ;
SetARange(false,thePrefs.GetMaxGraphUploadRate());
m_UploadOMeter.SetYUnits(GetResString(IDS_KBYTESEC)) ;
// Setup additional graph-scope
GetDlgItem(IDC_STATSSCOPE)->GetWindowRect(rect) ;
ScreenToClient(rect) ;
m_Statistics.Create(WS_VISIBLE | WS_CHILD, rect, this) ;
m_Statistics.SetRanges(0, thePrefs.GetStatsMax()) ;
m_Statistics.autofitYscale=false;
// Set the trend ratio of the Active Connections trend in the Connection Statistics scope.
m_Statistics.SetTrendRatio(0, thePrefs.GetStatsConnectionsGraphRatio());
m_Statistics.SetYUnits(_T(""));
m_Statistics.SetXUnits(GetResString(IDS_TIME));
RepaintMeters();
m_Statistics.SetBackgroundColor(thePrefs.GetStatsColor(0)) ;
m_Statistics.SetGridColor(thePrefs.GetStatsColor(1)) ;
m_DownloadOMeter.InvalidateCtrl();
m_UploadOMeter.InvalidateCtrl();
m_Statistics.InvalidateCtrl();
if (thePrefs.GetStatsInterval()==0)
GetDlgItem(IDC_STATTREE)->EnableWindow(false);
UpdateData(FALSE);
EnableWindow( TRUE );
m_ilastMaxConnReached = 0;
CRect rcW,rcSpl,rcTree,rcDown,rcUp,rcStat;
GetWindowRect(rcW);
ScreenToClient(rcW);
CWnd* pWnd = GetDlgItem(IDC_STATTREE);
pWnd->GetWindowRect(rcTree);
ScreenToClient(rcTree);
m_DownloadOMeter.GetWindowRect(rcDown);
ScreenToClient(rcDown);
m_UploadOMeter.GetWindowRect(rcUp);
ScreenToClient(rcUp);
m_Statistics.GetWindowRect(rcStat);
ScreenToClient(rcStat);
//vertical splitter
rcSpl.left=rcTree.right+1; rcSpl.right=rcSpl.left+4; rcSpl.top=rcW.top+2; rcSpl.bottom=rcW.bottom-5;
m_wndSplitterstat.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT);
int PosStatVinitX = rcSpl.left;
int PosStatVnewX = thePrefs.GetSplitterbarPositionStat()*rcW.Width()/100;
int maxX = rcW.right-13;
int minX = rcW.left+8;
if (thePrefs.GetSplitterbarPositionStat() > 90)
PosStatVnewX = maxX;
else if (thePrefs.GetSplitterbarPositionStat() < 10)
PosStatVnewX = minX;
rcSpl.left = PosStatVnewX;
rcSpl.right = PosStatVnewX+4;
m_wndSplitterstat.MoveWindow(rcSpl);
//HR splitter
rcSpl.left=rcDown.left;
rcSpl.right=rcDown.right;
rcSpl.top=rcDown.bottom+1;
rcSpl.bottom=rcSpl.top+4;
m_wndSplitterstat_HR.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT_HR);
int PosStatVinitZ = rcSpl.top;
int PosStatVnewZ = thePrefs.GetSplitterbarPositionStat_HR()*rcW.Height()/100;
int maxZ = rcW.bottom-14;
int minZ = 0;
if (thePrefs.GetSplitterbarPositionStat_HR() > 90)
PosStatVnewZ = maxZ;
else if (thePrefs.GetSplitterbarPositionStat_HR() < 10)
PosStatVnewZ = minZ;
rcSpl.top = PosStatVnewZ;
rcSpl.bottom = PosStatVnewZ+4;
m_wndSplitterstat_HR.MoveWindow(rcSpl);
//HL splitter
rcSpl.left=rcUp.left;
rcSpl.right=rcUp.right;
rcSpl.top=rcUp.bottom+1;
rcSpl.bottom=rcSpl.top+4;
m_wndSplitterstat_HL.Create(WS_CHILD | WS_VISIBLE, rcSpl, this, IDC_SPLITTER_STAT_HL);
int PosStatVinitY = rcSpl.top;
int PosStatVnewY = thePrefs.GetSplitterbarPositionStat_HL()*rcW.Height()/100;
int maxY = rcW.bottom-9;
int minY = 10;
if (thePrefs.GetSplitterbarPositionStat_HL() > 90)
PosStatVnewY = maxY;
else if (thePrefs.GetSplitterbarPositionStat_HL() < 10)
PosStatVnewY = minY;
rcSpl.top = PosStatVnewY;
rcSpl.bottom = PosStatVnewY+4;
m_wndSplitterstat_HL.MoveWindow(rcSpl);
int var = 0;
DoResize_V(PosStatVnewX - PosStatVinitX);
DoResize_HL(PosStatVnewY - PosStatVinitY);
DoResize_HR(PosStatVnewZ - PosStatVinitZ);
Localize();
ShowStatistics(true);
return true;
}
void CStatisticsDlg::initCSize()
{
uint8 x = thePrefs.GetSplitterbarPositionStat();
uint8 y = thePrefs.GetSplitterbarPositionStat_HL();
uint8 z = thePrefs.GetSplitterbarPositionStat_HR();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -