📄 processdlg.cpp
字号:
HBRUSH CPROCESSDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
// TODO: Change any attributes of the DC here
COLORREF clr = RGB(55,30,60);
pDC->SetTextColor(clr); //设置红色的文本
clr = RGB(186,86,106);
pDC->SetBkColor(clr); //设置黑色的背景
HBRUSH m_brMine = ::CreateSolidBrush(clr);
return m_brMine;
// TODO: Return a different brush if the default is not desired
//return hbr;
}
void CPROCESSDlg::Bolcked_Insert(PCB *item)
{
if(Ordiary_BlockList->next == NULL) //若链表为空,则插在第一个位置
{
item->next = Ordiary_BlockList->next;
Ordiary_BlockList->next = item;
}
else //否则插在最后一个位置
{
struct PCB * p;
p = Ordiary_BlockList->next;
while(p->next != NULL)
p = p->next;
p->next = item;
item->next = NULL; //插入
}
}
void CPROCESSDlg::ShowBlocked()
{
m_ListCtrl_Blocked.DeleteAllItems();
struct PCB * p = Ordiary_BlockList->next;
int k = 0;
while(p != NULL)
{
CString m_str ;
m_str = p->processName;
m_ListCtrl_Blocked.InsertItem(k,m_str,0); //插入进程名字
m_str.Format("%d",p->processID);
m_ListCtrl_Blocked.SetItemText(k,1,m_str); //插入进程标识符
m_str = p->state;
m_ListCtrl_Blocked.SetItemText(k,2,m_str); //插入进程状态
m_str.Format("%d",p->priority);
m_ListCtrl_Blocked.SetItemText(k,3,m_str); //插入进程优先权值
m_str = p->kind;
m_ListCtrl_Blocked.SetItemText(k,4,m_str); //插入进程种类
m_str.Format("%d",p->needTime);
m_ListCtrl_Blocked.SetItemText(k,5,m_str); //插入进程所需时间
m_str.Format("%d",p->StartAddress);
m_ListCtrl_Blocked.SetItemText(k,6,m_str); //插入进程所需时间
m_str = p->blockedReason;
m_ListCtrl_Blocked.SetItemText(k,7,m_str); //插入进程阻塞原因
k++;
p = p->next;
}
}
//撤销正在执行的进程
void CPROCESSDlg::OnDblclkList4(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
if(Ordiary_ReadyList->next != NULL) //如果就绪队列不为空,则重新进行进程调度
ExecutingProcess();
*pResult = 0;
}
//撤销阻塞队列中的进程
void CPROCESSDlg::OnDblclkList3(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int item = pNMListView->iItem;
int id = atoi(m_ListCtrl_Blocked.GetItemText(item,1));//得到正在执行进程的标识符
struct PCB * p = Ordiary_BlockList->next;
struct PCB * q = Ordiary_BlockList;
while(p->processID != id) //从阻塞进程中删除该进程
{
q = p;
p = p->next;
}
this->Release(p);
q->next = p->next;
ShowBlocked(); //显示剩余的阻塞进程
if(Ordiary_ReadyList->next != NULL) //如果就绪队列不为空,则重新进行进程调度
ExecutingProcess();
*pResult = 0;
}
//撤销就绪队列(分时进程和批处理)中的进程
void CPROCESSDlg::OnDblclkList2(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int item = pNMListView->iItem;
int id = atoi(m_ListCtrl_Ordinary.GetItemText(item,1));//得到就绪队列(分时进程和批处理)中进程的标识符
struct PCB * p = Ordiary_ReadyList->next;
struct PCB * q = Ordiary_ReadyList;
while(p->processID != id) //从就绪队列(分时进程和批处理)中删除该进程
{
q = p;
p = p->next;
}
this->Release(p);
q->next = p->next;
ShowBlocked(); //显示剩余的阻塞进程
if(Ordiary_ReadyList->next != NULL) //如果就绪队列不为空,则重新进行进程调度
ExecutingProcess();
*pResult = 0;
}
//撤销实时进程队列中的进程
void CPROCESSDlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
int item = pNMListView->iItem;
int priority = atoi(m_ListCtrl_Process.GetItemText(item,3));//得到实时队列中进程的标识符
if(priority > 0)
{
AfxMessageBox("实时进程不能被撤销!");
return;
}
*pResult = 0;
}
//从就绪队列中找到第一个因打印机忙而被阻塞的进程并将其唤醒
void CPROCESSDlg::GetBlocked_Printer()
{
struct PCB * p = Ordiary_BlockList->next;
struct PCB * q = Ordiary_BlockList;
while((p != NULL)&&(strcmp(p->blockedReason ,"Printer")))
{
q = p;
p = p->next;
}
if(p == NULL)
return;
q->next = p->next;
if(!::strcmp(p->kind,"实时进程"))
RealTime_Insert(p);
else
Ordinary_Insert(p);
ShowBlocked();
ShowOrdinary();
ShowRealTime();
//如果就绪队列不为空且无正在运行的程序,则重新进行进程调度
if(((Ordiary_ReadyList->next != NULL)||(RealTime_ReadyList->next != NULL))&&(m_TimePieceRun.GetPos() == 0))
ExecutingProcess();
}
//从就绪队列中找到第一个因新数据尚未到达而被阻塞的进程并将其唤醒
void CPROCESSDlg::GetBlocked_NewData()
{
struct PCB * p = Ordiary_BlockList->next;
struct PCB * q = Ordiary_BlockList;
while((p != NULL)&&(strcmp(p->blockedReason ,"New data")))
{
q = p;
p = p->next;
}
if(p == NULL)
return;
q->next = p->next;
if(!::strcmp(p->kind,"实时进程"))
RealTime_Insert(p);
else
Ordinary_Insert(p);
ShowBlocked();
ShowRealTime();
ShowOrdinary();
//如果就绪队列不为空且无正在运行的程序,则重新进行进程调度
if(((Ordiary_ReadyList->next != NULL)||(RealTime_ReadyList->next != NULL))&&(m_TimePieceRun.GetPos() == 0))
ExecutingProcess();
}
//从就绪队列中找到第一个因启动新的操作而被阻塞的进程并将其唤醒
void CPROCESSDlg::GetBlocked_NewOperation()
{
struct PCB * p = Ordiary_BlockList->next;
struct PCB * q = Ordiary_BlockList;
while((p != NULL)&&(strcmp(p->blockedReason ,"New operarion")))
{
q = p;
p = p->next;
}
if(p == NULL)
return;
q->next = p->next;
if(!::strcmp(p->kind,"实时进程"))
RealTime_Insert(p);
else
Ordinary_Insert(p);
ShowBlocked();
ShowOrdinary();
ShowRealTime();
//如果就绪队列不为空且无正在运行的程序,则重新进行进程调度
if(((Ordiary_ReadyList->next != NULL)||(RealTime_ReadyList->next != NULL))&&(m_TimePieceRun.GetPos() == 0))
ExecutingProcess();
}
void CPROCESSDlg::OnMemory()
{
// TODO: Add your control notification handler code here
// CMemoryDlg dlg;
dlg.M = M;
m_isClick = TRUE;
dlg.DoModal();
m_isClick = FALSE;
}
//为新建的进程分配合适的分区
bool CPROCESSDlg::LookForPartition(struct PCB * pcb)
{
if((M.PartitionA.size >= pcb->occupySize)&&(M.PartitionA.isUse))
{
pcb->StartAddress = M.PartitionA.startAddr;
M.PartitionA.isUse = false;
return true;
}
else
if((M.PartitionB.size >= pcb->occupySize)&&(M.PartitionB.isUse))
{
pcb->StartAddress = M.PartitionB.startAddr;
M.PartitionB.isUse = false;
return true;
}
else
if((M.PartitionC.size >= pcb->occupySize)&&(M.PartitionC.isUse))
{
pcb->StartAddress = M.PartitionC.startAddr;
M.PartitionC.isUse = false;
return true;
}
else
if((M.PartitionD.size >= pcb->occupySize)&&(M.PartitionD.isUse))
{
pcb->StartAddress = M.PartitionD.startAddr;
M.PartitionD.isUse = false;
return true;
}
else
if((M.PartitionE.size >= pcb->occupySize)&&(M.PartitionE.isUse))
{
pcb->StartAddress = M.PartitionE.startAddr;
M.PartitionE.isUse = false;
return true;
}
else
if((M.PartitionF.size >= pcb->occupySize)&&(M.PartitionF.isUse))
{
pcb->StartAddress = M.PartitionF.startAddr;
M.PartitionF.isUse = false;
return true;
}
else
if((M.PartitionG.size >= pcb->occupySize)&&(M.PartitionG.isUse))
{
pcb->StartAddress = M.PartitionG.startAddr;
M.PartitionG.isUse = false;
return true;
}
else
if((M.PartitionH.size >= pcb->occupySize)&&(M.PartitionH.isUse))
{
pcb->StartAddress = M.PartitionH.startAddr;
M.PartitionH.isUse = false;
return true;
}
else
if((M.PartitionI.size >= pcb->occupySize)&&(M.PartitionI.isUse))
{
pcb->StartAddress = M.PartitionI.startAddr;
M.PartitionI.isUse = false;
return true;
}
else
if((M.PartitionJ.size >= pcb->occupySize)&&(M.PartitionJ.isUse))
{
pcb->StartAddress = M.PartitionJ.startAddr;
M.PartitionJ.isUse = false;
return true;
}
else
return false;
return true;
}
void CPROCESSDlg::Release(PCB *pcb)
{
if(M.PartitionA.startAddr == pcb->StartAddress)
{
M.PartitionA.isUse = true;
}
if(M.PartitionB.startAddr == pcb->StartAddress)
{
M.PartitionB.isUse = true;
}
if(M.PartitionC.startAddr == pcb->StartAddress)
{
M.PartitionC.isUse = true;
}
if(M.PartitionD.startAddr == pcb->StartAddress)
{
M.PartitionD.isUse = true;
}
if(M.PartitionE.startAddr == pcb->StartAddress)
{
M.PartitionE.isUse = true;
}
if(M.PartitionF.startAddr == pcb->StartAddress)
{
M.PartitionF.isUse = true;
}
if(M.PartitionG.startAddr == pcb->StartAddress)
{
M.PartitionG.isUse = true;
}
if(M.PartitionH.startAddr == pcb->StartAddress)
{
M.PartitionH.isUse = true;
}
if(M.PartitionI.startAddr == pcb->StartAddress)
{
M.PartitionI.isUse = true;
}
if(M.PartitionJ.startAddr == pcb->StartAddress)
{
M.PartitionJ.isUse = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -