📄 system2dlg.cpp
字号:
this->SetDlgItemText(IDC_EDIT_PSTATE3,getState(m_process[n].state));
str.Format("%d",m_process[n].priority);
this->SetDlgItemText(IDC_EDIT_PPRI3,str);
str.Format("%d",m_process[n].life);
this->SetDlgItemText(IDC_EDIT_PLIFE3,str);
break;
case 3:
str.Format("%d",m_process[n].id);
this->SetDlgItemText(IDC_EDIT_PID4,str);
this->SetDlgItemText(IDC_EDIT_PSTATE4,getState(m_process[n].state));
str.Format("%d",m_process[n].priority);
this->SetDlgItemText(IDC_EDIT_PPRI4,str);
str.Format("%d",m_process[n].life);
this->SetDlgItemText(IDC_EDIT_PLIFE4,str);
break;
case 4:
str.Format("%d",m_process[n].id);
this->SetDlgItemText(IDC_EDIT_PID5,str);
this->SetDlgItemText(IDC_EDIT_PSTATE5,getState(m_process[n].state));
str.Format("%d",m_process[n].priority);
this->SetDlgItemText(IDC_EDIT_PPRI5,str);
str.Format("%d",m_process[n].life);
this->SetDlgItemText(IDC_EDIT_PLIFE5,str);
break;
}
}
void CSystem2Dlg::KillProcess(int n)
{
m_process[n].id=0;
m_process[n].state=0;
m_process[n].priority=0;
m_process[n].life=0;
switch(n)
{
case 0:
this->SetDlgItemText(IDC_EDIT_PID1,"");
this->SetDlgItemText(IDC_EDIT_PSTATE1,"");
this->SetDlgItemText(IDC_EDIT_PPRI1,"");
this->SetDlgItemText(IDC_EDIT_PLIFE1,"");
break;
case 1:
this->SetDlgItemText(IDC_EDIT_PID2,"");
this->SetDlgItemText(IDC_EDIT_PSTATE2,"");
this->SetDlgItemText(IDC_EDIT_PPRI2,"");
this->SetDlgItemText(IDC_EDIT_PLIFE2,"");
break;
case 2:
this->SetDlgItemText(IDC_EDIT_PID3,"");
this->SetDlgItemText(IDC_EDIT_PSTATE3,"");
this->SetDlgItemText(IDC_EDIT_PPRI3,"");
this->SetDlgItemText(IDC_EDIT_PLIFE3,"");
break;
case 3:
this->SetDlgItemText(IDC_EDIT_PID4,"");
this->SetDlgItemText(IDC_EDIT_PSTATE4,"");
this->SetDlgItemText(IDC_EDIT_PPRI4,"");
this->SetDlgItemText(IDC_EDIT_PLIFE4,"");
break;
case 4:
this->SetDlgItemText(IDC_EDIT_PID5,"");
this->SetDlgItemText(IDC_EDIT_PSTATE5,"");
this->SetDlgItemText(IDC_EDIT_PPRI5,"");
this->SetDlgItemText(IDC_EDIT_PLIFE5,"");
break;
}
}
//选择优先级高的进程为活动进程
void CSystem2Dlg::ChooseProcess()
{
int max=-1;
for(int i=0;i<5;i++)
{
if(m_process[i].state==4)continue; //FINISH=4
if(m_process[i].state==3)continue; //SLEEP=3
if(max<m_process[i].priority)
{
max=m_process[i].priority;
this->m_ActionProcess=i;
}
}
if(m_process[m_ActionProcess].state==3)return;
if(m_process[m_ActionProcess].state==4)return;
////////
for(i=0;i<5;i++)
if(m_process[i].state==2)
m_process[i].state=READY;
////////
this->Processing();
}
//处理活动进程
void CSystem2Dlg::Processing()
{
m_process[this->m_ActionProcess].state=RUN;
if(m_process[this->m_ActionProcess].life==0)
{
m_process[this->m_ActionProcess].state=FINISH;
return;
}
m_process[this->m_ActionProcess].life--;
if(m_process[this->m_ActionProcess].life%50==0)
if(m_process[this->m_ActionProcess].priority>0)
m_process[this->m_ActionProcess].priority--;
}
void CSystem2Dlg::OnBtnCreate1()
{
// TODO: Add your control notification handler code here
if(!this->m_IsCreate[0])
{
this->CreateProcess(0);
this->SetDlgItemText(ID_BTN_CREATE1,"杀死进程");
this->m_IsCreate[0]=true;
this->GetDlgItem(ID_BTN_SLEEP1)->EnableWindow(true);
this->m_IsSleep[0]=false;
this->UpdateProcess(0);
}
else
{
this->SetDlgItemText(ID_BTN_CREATE1,"新建进程");
this->m_IsCreate[0]=false;
this->GetDlgItem(ID_BTN_SLEEP1)->EnableWindow(false);
this->SetDlgItemText(ID_BTN_SLEEP1,"挂起进程");
this->KillProcess(0);
}
}
void CSystem2Dlg::OnBtnSleep1()
{
// TODO: Add your control notification handler code here
if(!this->m_IsSleep[0])
{
//挂起进程
this->SetDlgItemText(ID_BTN_SLEEP1,"恢复进程");
this->m_process[0].state=SLEEP;
this->m_IsSleep[0]=true;
}
else
{
//恢复进程
this->SetDlgItemText(ID_BTN_SLEEP1,"挂起进程");
this->m_IsSleep[0]=false;
this->m_process[0].state=READY;
}
}
void CSystem2Dlg::OnBtnCreate2()
{
// TODO: Add your control notification handler code here
if(!this->m_IsCreate[1])
{
this->CreateProcess(1);
this->SetDlgItemText(ID_BTN_CREATE2,"杀死进程");
this->m_IsCreate[1]=true;
this->GetDlgItem(ID_BTN_SLEEP2)->EnableWindow(true);
this->m_IsSleep[1]=false;
this->UpdateProcess(1);
}
else
{
this->SetDlgItemText(ID_BTN_CREATE2,"新建进程");
this->m_IsCreate[1]=false;
this->GetDlgItem(ID_BTN_SLEEP2)->EnableWindow(false);
this->SetDlgItemText(ID_BTN_SLEEP2,"挂起进程");
this->KillProcess(1);
}
}
void CSystem2Dlg::OnBtnSleep2()
{
// TODO: Add your control notification handler code here
if(!this->m_IsSleep[1])
{
//挂起进程
this->SetDlgItemText(ID_BTN_SLEEP2,"恢复进程");
this->m_process[1].state=SLEEP;
this->m_IsSleep[1]=true;
}
else
{
//恢复进程
this->SetDlgItemText(ID_BTN_SLEEP2,"挂起进程");
this->m_IsSleep[1]=false;
this->m_process[1].state=READY;
}
}
void CSystem2Dlg::OnBtnCreate3()
{
// TODO: Add your control notification handler code here
if(!this->m_IsCreate[2])
{
this->CreateProcess(2);
this->SetDlgItemText(ID_BTN_CREATE3,"杀死进程");
this->m_IsCreate[2]=true;
this->GetDlgItem(ID_BTN_SLEEP3)->EnableWindow(true);
this->m_IsSleep[2]=false;
this->UpdateProcess(2);
}
else
{
this->SetDlgItemText(ID_BTN_CREATE3,"新建进程");
this->m_IsCreate[2]=false;
this->GetDlgItem(ID_BTN_SLEEP3)->EnableWindow(false);
this->SetDlgItemText(ID_BTN_SLEEP3,"挂起进程");
this->KillProcess(2);
}
}
void CSystem2Dlg::OnBtnSleep3()
{
// TODO: Add your control notification handler code here
if(!this->m_IsSleep[2])
{
//挂起进程
this->SetDlgItemText(ID_BTN_SLEEP3,"恢复进程");
this->m_process[2].state=SLEEP;
this->m_IsSleep[2]=true;
}
else
{
//恢复进程
this->SetDlgItemText(ID_BTN_SLEEP3,"挂起进程");
this->m_IsSleep[2]=false;
this->m_process[2].state=READY;
}
}
void CSystem2Dlg::OnBtnCreate4()
{
// TODO: Add your control notification handler code here
if(!this->m_IsCreate[3])
{
this->CreateProcess(3);
this->SetDlgItemText(ID_BTN_CREATE4,"杀死进程");
this->m_IsCreate[3]=true;
this->GetDlgItem(ID_BTN_SLEEP4)->EnableWindow(true);
this->m_IsSleep[3]=false;
this->UpdateProcess(3);
}
else
{
this->SetDlgItemText(ID_BTN_CREATE4,"新建进程");
this->m_IsCreate[3]=false;
this->GetDlgItem(ID_BTN_SLEEP4)->EnableWindow(false);
this->SetDlgItemText(ID_BTN_SLEEP4,"挂起进程");
this->KillProcess(3);
}
}
void CSystem2Dlg::OnBtnSleep4()
{
// TODO: Add your control notification handler code here
if(!this->m_IsSleep[3])
{
//挂起进程
this->SetDlgItemText(ID_BTN_SLEEP4,"恢复进程");
this->m_process[3].state=SLEEP;
this->m_IsSleep[3]=true;
}
else
{
//恢复进程
this->SetDlgItemText(ID_BTN_SLEEP4,"挂起进程");
this->m_IsSleep[3]=false;
this->m_process[3].state=READY;
}
}
void CSystem2Dlg::OnBtnCreate5()
{
// TODO: Add your control notification handler code here
if(!this->m_IsCreate[4])
{
this->CreateProcess(4);
this->SetDlgItemText(ID_BTN_CREATE5,"杀死进程");
this->m_IsCreate[4]=true;
this->GetDlgItem(ID_BTN_SLEEP5)->EnableWindow(true);
this->m_IsSleep[4]=false;
this->UpdateProcess(4);
}
else
{
this->SetDlgItemText(ID_BTN_CREATE5,"新建进程");
this->m_IsCreate[4]=false;
this->GetDlgItem(ID_BTN_SLEEP5)->EnableWindow(false);
this->SetDlgItemText(ID_BTN_SLEEP5,"挂起进程");
this->KillProcess(4);
}
}
void CSystem2Dlg::OnBtnSleep5()
{
// TODO: Add your control notification handler code here
if(!this->m_IsSleep[4])
{
//挂起进程
this->SetDlgItemText(ID_BTN_SLEEP5,"恢复进程");
this->m_process[4].state=SLEEP;
this->m_IsSleep[4]=true;
}
else
{
//恢复进程
this->SetDlgItemText(ID_BTN_SLEEP5,"挂起进程");
this->m_IsSleep[4]=false;
this->m_process[4].state=READY;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -