📄 pmonitordlg.cpp
字号:
ctitle6->ShowWindow(SW_HIDE);
cvalue6->ShowWindow(SW_HIDE);
cntitle6->ShowWindow(SW_HIDE);
cnvalue6->ShowWindow(SW_HIDE);
cutitle6->ShowWindow(SW_HIDE);
cuvalue6->ShowWindow(SW_HIDE);
}
}
int CPMonitorDlg::DrawDynBg(UINT nID1, UINT nID2)
{
int result=0;
CWnd *pWnd=this->GetDlgItem(nID1);
CDC *pDC1=pWnd->GetDC();
CRect rc;
pWnd->GetWindowRect(&rc);
int width1=rc.Width()-2;
int height1=rc.Height()-2;
pWnd=this->GetDlgItem(nID2);
CDC *pDC2=pWnd->GetDC();
pWnd->GetWindowRect(&rc);
int width2=rc.Width()-2;
int height2=rc.Height()-2;
pDC1->FillSolidRect(0,0,width1,height1,RGB(0,0,0));
pDC2->FillSolidRect(0,0,width2,height2,RGB(0,0,0));
int dx=width1/4;
int dy=height1/50;
int x0=dx;
int y0=5;
int x,y;
for(int i=0;i<50;i++)
{
x=x0;
y=y0+3*i;
for(int j=0;j<(dx-1)/2;j++)
{
pDC1->FillSolidRect(x+2*j,y,1,1,RGB(22,81,59));
pDC1->FillSolidRect(x+2*j+1,y+1,1,1,RGB(22,81,59));
}
x=x0+dx+1;
for(j=0;j<(dx-1)/2;j++)
{
pDC1->FillSolidRect(x+2*j,y,1,1,RGB(22,81,59));
pDC1->FillSolidRect(x+2*j+1,y+1,1,1,RGB(22,81,59));
}
}
result=y;
pDC1->FillSolidRect(x0,y+3,dx-1,1,RGB(2,252,4));
pDC1->FillSolidRect(x,y+3,dx-1,1,RGB(2,252,4));
dx=width2/20;
dy=dx;
x0=dx;
y0=dy;
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(22,81,59));
pDC2->SelectObject(&pen);
y=y0;
i=0;
while(y<height2)
{
pDC2->MoveTo(0,y);
pDC2->LineTo(width2,y);
i++;
y=y0+i*dy;
}
return result;
}
void CPMonitorDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int percent,i,length,value;
int *info;
CString str;
CProcessInfo *p;
CWnd *pWnd;
CDC *pDC1,*pDC2;
CRect rc1,rc2;
int y;
switch(nIDEvent)
{
case 1: //采集系统资源信息
if(index>0)
{
pWnd=this->GetDlgItem(IDC_DISKPIC1);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[0][0],diskvalue[0][1],IDC_DISKPIC1);
}
if(index>1)
{
pWnd=this->GetDlgItem(IDC_DISKPIC2);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[1][0],diskvalue[1][1],IDC_DISKPIC2);
}
if(index>2)
{
pWnd=this->GetDlgItem(IDC_DISKPIC3);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[2][0],diskvalue[2][1],IDC_DISKPIC3);
}
if(index>3)
{
pWnd=this->GetDlgItem(IDC_DISKPIC4);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[3][0],diskvalue[3][1],IDC_DISKPIC4);
}
if(index>4)
{
pWnd=this->GetDlgItem(IDC_DISKPIC5);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[4][0],diskvalue[4][1],IDC_DISKPIC5);
}
if(index>5)
{
pWnd=this->GetDlgItem(IDC_DISKPIC6);
pWnd->UpdateWindow();
this->DrawDiskInfo(diskvalue[5][0],diskvalue[5][1],IDC_DISKPIC6);
}
break;
case 2: //采集进程信息
i=0;
m_list.DeleteAllItems();
pInfo=&sys->getProcessInfo();
p=pInfo;
while(p!=NULL)
{
str=p->getProcessName();
m_list.InsertItem(i,str);
str.Format("%d",p->getPCpuSize());
m_list.SetItemText(i,1,str);
str.Format("%d",p->getPMemorySize());
length=str.GetLength();
if(length>3)
{
str=str.Left(length-3)+","+str.Right(3);
}
m_list.SetItemText(i,2,str+" K");
p=p->next;
i++;
}
break;
case 3: //采集CPU信息
percent=sys->getCpuUsedRadio();
y=this->DrawDynBg(IDC_DYNCOL1,IDC_DYNPLOY1);
if(cpu_count==5)
{
cpu_count=0;
}
pWnd=this->GetDlgItem(IDC_DYNCOL1);
pDC1=pWnd->GetDC();
pWnd->GetWindowRect(&rc1);
pWnd->UpdateWindow();
pWnd=GetDlgItem(IDC_DYNPLOY1);
pDC2=pWnd->GetDC();
pWnd->GetWindowRect(&rc2);
pWnd->UpdateWindow();
str.Format("%d",percent);
str+="%";
this->DrawDynGraph(pDC1,pDC2,rc1,rc2,y,cpu_count,percent,0,str);
cpu_count++;
break;
case 4: //采集内存信息
y=this->DrawDynBg(IDC_DYNCOL2,IDC_DYNPLOY2);
pWnd=this->GetDlgItem(IDC_DYNCOL2);
pDC1=pWnd->GetDC();
pWnd->GetWindowRect(&rc1);
pWnd->UpdateWindow();
pWnd=GetDlgItem(IDC_DYNPLOY2);
pDC2=pWnd->GetDC();
pWnd->GetWindowRect(&rc2);
pWnd->UpdateWindow();
info=sys->getMemoryUsedInfo();
if(memory_count==5)
{
memory_count=0;
}
str.Format("%d",info[0]);
this->DrawDynGraph(pDC1,pDC2,rc1,rc2,y,memory_count,info[1],1,str);
memory_count++;
break;
case 5: //采集网络流入量信息
value=sys->getNetWorkInput();
y=this->DrawDynBg(IDC_DYNCOL3,IDC_DYNPLOY3);
if(input_count==5)
{
input_count=0;
}
pWnd=this->GetDlgItem(IDC_DYNCOL3);
pDC1=pWnd->GetDC();
pWnd->GetWindowRect(&rc1);
pWnd->UpdateWindow();
pWnd=GetDlgItem(IDC_DYNPLOY3);
pDC2=pWnd->GetDC();
pWnd->GetWindowRect(&rc2);
pWnd->UpdateWindow();
if(value>1024*100||value<0)
{
value=100;
}
else
{
value=value/1024;
}
str.Format("%d",value);
percent=(int)(((float)value/100)*100);
if(percent>100||percent<0)
{
percent=100;
}
this->DrawDynGraph(pDC1,pDC2,rc1,rc2,y,input_count,percent,2,str);
input_count++;
break;
case 6: //采集网络流出量信息
value=sys->getNetWorkOutput();
y=this->DrawDynBg(IDC_DYNCOL4,IDC_DYNPLOY4);
if(output_count==5)
{
output_count=0;
}
pWnd=this->GetDlgItem(IDC_DYNCOL4);
pDC1=pWnd->GetDC();
pWnd->GetWindowRect(&rc1);
pWnd->UpdateWindow();
pWnd=GetDlgItem(IDC_DYNPLOY4);
pDC2=pWnd->GetDC();
pWnd->GetWindowRect(&rc2);
pWnd->UpdateWindow();
if(value>1024*100||value<0)
{
value=100;
}
else
{
value=value/1024;
}
str.Format("%d",value);
percent=(int)(((float)value/100)*100);
if(percent>100||percent<0)
{
percent=100;
}
this->DrawDynGraph(pDC1,pDC2,rc1,rc2,y,output_count,percent,3,str);
output_count++;
}
CDialog::OnTimer(nIDEvent);
}
void CPMonitorDlg::DrawDynGraph(CDC *pDC1, CDC *pDC2, CRect rc1, CRect rc2, UINT ypos,UINT xpos, UINT percent, UINT nID,CString drawText)
{
int width=rc1.Width()-2;
int heigth=rc1.Height()-2;
int dx=width/4;
int x,y;
for(int i=0;i<(int)percent/2;i++)
{
x=dx;
y=ypos-3*i;
pDC1->FillSolidRect(x,y,dx-1,2,RGB(2,252,4));
x=dx*2+1;
pDC1->FillSolidRect(x,y,dx-1,2,RGB(2,252,4));
}
pDC1->DrawText(drawText,new CRect(0,ypos+6,width,heigth),DT_CENTER);
width=rc2.Width()-2;
heigth=rc2.Height()-2;
dx=width/20;
x=width-xpos*(dx/5);
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(22,81,59));
pDC2->SelectObject(&pen);
while(x>0)
{
pDC2->MoveTo(x,0);
pDC2->LineTo(x,heigth);
x-=dx;
}
CPen pen1;
pen1.CreatePen(PS_SOLID,1,RGB(2,252,4));
pDC2->SelectObject(&pen1);
int value=(int)(((float)heigth/100)*percent);
switch(nID)
{
case 0:
for(i=0;i<100;i++)
{
cpoint[i].y=cpoint[i+1].y;
pervalue[nID][i]=pervalue[nID][i+1];
}
cpoint[100].y=heigth-value;
this->DrawPolyline(pDC2,cpoint,nID);
break;
case 1:
for(i=0;i<100;i++)
{
mpoint[i].y=mpoint[i+1].y;
pervalue[nID][i]=pervalue[nID][i+1];
}
mpoint[100].y=heigth-value;
this->DrawPolyline(pDC2,mpoint,nID);
break;
case 2:
for(i=0;i<100;i++)
{
ipoint[i].y=ipoint[i+1].y;
pervalue[nID][i]=pervalue[nID][i+1];
}
ipoint[100].y=heigth-value;
this->DrawPolyline(pDC2,ipoint,nID);
break;
case 3:
for(i=0;i<100;i++)
{
opoint[i].y=opoint[i+1].y;
pervalue[nID][i]=pervalue[nID][i+1];
}
opoint[100].y=heigth-value;
this->DrawPolyline(pDC2,opoint,nID);
}
pervalue[nID][100]=percent;
}
void CPMonitorDlg::DrawPolyline(CDC *pDC, CPoint *point, UINT nID)
{
int start,end;
int sl,el,j;
CString str,str1;
CPoint oldp,currentp;
COLORREF clr;
for(int i=0;i<100;i++)
{
start=pervalue[nID][i];
end=pervalue[nID][i+1];
if(start==0&&end==0)
{
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
pDC->SelectObject(&pen);
pDC->MoveTo(point[i]);
pDC->LineTo(point[i+1]);
}
else
{
sl=this->CheckColor(start,nID);
el=this->CheckColor(end,nID);
if(sl<=el)
{
oldp=point[i];
for(j=sl;j<=el;j++)
{
if(level[nID][j]>0)
{
clr=color[nID][j];
CPen pen1;
pen1.CreatePen(PS_SOLID,1,clr);
pDC->SelectObject(&pen1);
pDC->MoveTo(oldp);
if(level[nID][j]<end)
{
currentp.x=point[i+1].x-(int)(((float)(point[i+1].x-point[i].x)*(end-level[nID][j]))/(end-start));
currentp.y=185-(int)(((float)185/100)*level[nID][j]);
/*str.Format("(%d,%d)",oldp.x,oldp.y);
str1.Format("(%d,%d)",currentp.x,currentp.y);
str=str+"->"+str1+" ****11*****";
str1.Format("(%d,%d,%d)",start,level[nID][j],end);
str+=str1;
str1.Format("(%d,%d,%d)",sl,j,el);
str+=str1+"\r\n";
file->Write(str,str.GetLength());*/
pDC->LineTo(currentp);
oldp=currentp;
}
else
{
/*str.Format("(%d,%d)",oldp.x,oldp.y);
str1.Format("(%d,%d)",point[i+1].x,point[i+1].y);
str=str+"->"+str1+" 1111\r\n";
file->Write(str,str.GetLength());*/
pDC->LineTo(point[i+1]);
}
}
}
}
else
{
oldp=point[i];
for(j=sl;j>=el;j--)
{
if(level[nID][j]>0)
{
clr=color[nID][j];
CPen pen1;
pen1.CreatePen(PS_SOLID,1,clr);
pDC->SelectObject(&pen1);
pDC->MoveTo(oldp);
if(level[nID][j]>end&&j!=el)
{
for(int k=j-1;k>=el;k--)
{
if(level[nID][k]>0)
{
break;
}
}
currentp.x=point[i+1].x-(int)(((float)(point[i+1].x-point[i].x)*(end-level[nID][k]))/(end-start));
currentp.y=185-(int)(((float)185/100)*level[nID][k]);
/*str.Format("(%d,%d)",oldp.x,oldp.y);
str1.Format("(%d,%d)",currentp.x,currentp.y);
str=str+"->"+str1+" ****22*****";
str1.Format("(%d,%d,%d)",start,level[nID][k],end);
str+=str1;
str1.Format("(%d,%d,%d)",sl,k,el);
str+=str1+"\r\n";
file->Write(str,str.GetLength());*/
pDC->LineTo(currentp);
oldp=currentp;
}
else
{
/*str.Format("(%d,%d)",oldp.x,oldp.y);
str1.Format("(%d,%d)",point[i+1].x,point[i+1].y);
str=str+"->"+str1+" 2222\r\n";
file->Write(str,str.GetLength());*/
pDC->LineTo(point[i+1]);
}
}
}
}
}
}
//file->Write("\r\n",2);
}
int CPMonitorDlg::CheckColor(int pos, UINT nID)
{
for(int i=0;i<5;i++)
{
if(pos<=level[nID][i])
{
return i;
}
}
return -1;
}
void CPMonitorDlg::OnParamManage()
{
// TODO: Add your command handler code here
CParam subDialog;
subDialog.DoModal();
}
void CPMonitorDlg::OnMinUp()
{
// TODO: Add your command handler code here
CMINIFRAME *dia=new CMINIFRAME(this);
BOOL *flag=new BOOL(4);
flag[0]=cflag;
flag[1]=mflag;
flag[2]=niflag;
flag[3]=noflag;
dia->PassData(flag,COLCYC);
//CDialog::OnCancel();
this->ShowWindow(SW_HIDE);
dia->DoModal();
}
void CPMonitorDlg::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -