📄 osdlg.cpp
字号:
// osDlg.cpp : implementation file
//
#include "stdafx.h"
#include "os.h"
#include "osDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
class CAboutDlg : public CDialog
{
public:
CAboutDlg();
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAboutDlg)
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COsDlg dialog
COsDlg::COsDlg(CWnd* pParent /*=NULL*/)
: CDialog(COsDlg::IDD, pParent)
{
dwtime=0;
pcpu=new CCpu(&osdlg);
pmemory=new CMemory(&osdlg);
//{{AFX_DATA_INIT(COsDlg)
m_Password=0;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void COsDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(COsDlg)
DDX_Text(pDX, IDC_EDIT1, m_Password);
DDV_MinMaxLong(pDX, m_Password, 0, 99999999);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(COsDlg, CDialog)
//{{AFX_MSG_MAP(COsDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_SHOW_OS, OnShowOs)
ON_WM_TIMER()
ON_MESSAGE(WM_TIME_HALT,OnTimeHalt)
ON_MESSAGE(MM_INITREE,OnMmtree)
ON_EN_CHANGE(IDC_EDIT1, OnChangeEdit1)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// COsDlg message handlers
BOOL COsDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// Add "About..." menu item to system menu.
// IDM_ABOUTBOX must be in the system command range.
ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
ASSERT(IDM_ABOUTBOX < 0xF000);
CMenu* pSysMenu = GetSystemMenu(FALSE);
if (pSysMenu != NULL)
{
CString strAboutMenu;
strAboutMenu.LoadString(IDS_ABOUTBOX);
if (!strAboutMenu.IsEmpty())
{
pSysMenu->AppendMenu(MF_SEPARATOR);
pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
}
}
// Set the icon for this dialog. The framework does this automatically
// when the application's main window is not a dialog
SetIcon(m_hIcon, TRUE); // Set big icon
SetIcon(m_hIcon, FALSE); // Set small icon
// TODO: Add extra initialization here
SetTimer(1,10,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
void COsDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
else
{
CDialog::OnSysCommand(nID, lParam);
}
}
// If you add a minimize button to your dialog, you will need the code below
// to draw the icon. For MFC applications using the document/view model,
// this is automatically done for you by the framework.
void COsDlg::OnPaint()
{
if (IsIconic())
{
CPaintDC dc(this); // device context for painting
SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
// Center icon in client rectangle
int cxIcon = GetSystemMetrics(SM_CXICON);
int cyIcon = GetSystemMetrics(SM_CYICON);
CRect rect;
GetClientRect(&rect);
int x = (rect.Width() - cxIcon + 1) / 2;
int y = (rect.Height() - cyIcon + 1) / 2;
// Draw the icon
dc.DrawIcon(x, y, m_hIcon);
}
else
{
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR COsDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void COsDlg::OnShowOs()
{
// TODO: Add your control notification handler code here
if(m_Password!=12345678)
{
osdlg.ifonshow=1;
osdlg.ifinitlist=TRUE;
this->PostMessage(MM_INITREE);
osdlg.DoModal();
}
else
AfxMessageBox("请检查口令");
}
///////////////////////////////////////////////////////////////////////////////////////////
void COsDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
dwt++;
if(dwt==65500)dwt=0;
if(dwt%60==0){ //每一秒钟
dwtime++;
osdlg.m_showtime.Format("%d:%d:%d",(int)(dwtime/3600)%12,(int)(dwtime/60)%60,(int)dwtime%60);
//修改时间片////////////////////////////////////////////////////////////////////////////////
if(dwtime==1){
pcpu->CpuChooseprocess(pmemory); //调用选择进程函数
}
osdlg.m_itimeslice--;
if(osdlg.m_itimeslice==0){
osdlg.m_itimeslice=5;
this->SendMessage(WM_TIME_HALT,0,0);
}
osdlg.Updatashow();
pmemory->DealHalt();
pcpu->CpuRun(pmemory);
osdlg.Updataabc(pmemory->memory,pmemory->A,pmemory->B,pmemory->C);
}
if(osdlg.ifinput){ //判断是否有执行命令
osdlg.ifinput=FALSE;
Carryout(); //调用执行命令函数
}
////////////////////////////////////////////////////////////////////////////////////////////
CDialog::OnTimer(nIDEvent);
}
////////////////////////////////////////////////////////////////////////////////////////////
//时间中断,修改psw值
////////////////////////////////////////////////////////////////////////////////////////////
void COsDlg::OnTimeHalt(WPARAM wParam,LPARAM lParam)
{
pcpu->CpuSetpsw(0,1); //设置psw[0]为1 表示有中断
pcpu->CpuSetpsw(1,1); //设置psw[1]为1 表示中断类型为时间中断
}
void COsDlg::OnMmtree() //初始Tree列表
{
UpdataDiskTree();
UpdataShowInfo();
}
bool COsDlg::CD(CString strin,CString *strError) //执行CD命令
{
int strlength=strin.GetLength(); //获得命令的总长度
int index=strin.Find(' '); //返回空格键的索引
if(4<=strlength&&6>=strlength)
{
int lastlength=strlength-index-1;
char name[3]; //存参数
name[0]=strin.GetAt(index+1);
name[1]=name[2]=' ';
if(3==lastlength)
{
name[1]=strin.GetAt(index+2);
name[2]=strin.GetAt(index+3);
}
if(2==lastlength)
{
name[1]=strin.GetAt(index+2);
}
name[0]=strin.GetAt(index+1);
if(disk.CD(name,strError))
{
osdlg.m_strresult.Format("cd %c%c%c",name[0],name[1],name[2]);
return TRUE;
}
else
return FALSE;
}
else
{
strError->Format("cd 参数错误");
return FALSE;
}
}
bool COsDlg::PUB(CString strin,CString *strshow) //执行pub命令/显示目录
{
int nCount=disk.load.GetSize();
if(0==nCount)
return FALSE;
CString s;
char name[3];
List list;
name[0]=disk.Rootlist[disk.load[0]].name[0];
s.Format("%c\\",name[0]);
*strshow=s;
for(int i=1;i<nCount;i++)
{
disk.file.Seek(disk.load[i]*64,CFile::begin);
disk.file.Read(&list,sizeof(List));
name[0]=list.name[0];
name[1]=list.name[1];
name[2]=list.name[2];
s.Format("%c%c%c\\",name[0],name[1],name[2]);
*strshow+=s;
}
return TRUE;
}
bool COsDlg::Create(CString strin,CString *strError) //执行Create命令
{
int index=strin.Find(' '); //返回空格键的索引
char name[3];
int strlength=strin.GetLength(); //获得命令的总长度
if(12!=strlength)
{
strError->Format(" create 命令 参数错误");
return FALSE;
}
else
{
name[0]=strin.GetAt(index+1);
name[1]=strin.GetAt(index+2);
name[2]=strin.GetAt(index+3);
char postfix=strin.GetAt(index+5);
if(disk.Create(name,strError,postfix))
{
strError->Format("成功建立文件%c%c%c.%c",name[0],name[1],name[2],postfix);
UpdataDiskTree();
UpdataShowInfo();
}
else
return FALSE;
}
return TRUE;
}
bool COsDlg::Makdir(CString strin,CString *strError) //执行Makdir命令
{
int index=strin.Find(' '); //返回空格键的索引
char name[3];
int strlength=strin.GetLength(); //获得命令的总长度
if(10!=strlength)
{
strError->Format(" makdir 命令 参数错误");
return FALSE;
}
name[0]=strin.GetAt(index+1);
name[1]=strin.GetAt(index+2);
name[2]=strin.GetAt(index+3);
if(disk.Makdir(name,strError))
{
strError->Format("成功创建目录%c%c%c",name[0],name[1],name[2]);
UpdataDiskTree();
UpdataShowInfo();
}
else
return FALSE;
pmemory->Createprocess("makdir",dwtime);
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -