www.pudn.com > Mos.rar > MosDlg.cpp


// MosDlg.cpp : implementation file 
// Wrote by Wang Hao. Released March,2002. 
// Copyright (C) 2002 by Wang Hao. 
// All rights reserved. 
 
#include "stdafx.h" 
#include "Mos.h" 
#include "MosDlg.h" 
#include "HyperLink.h" 
#include "InputJobDlg.h" 
#include "Mos_io.h" 
#include "Mos_sw.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAboutDlg dialog used for App About 
extern CMos_io m_io; 
class CAboutDlg : public CDialog 
{ 
public: 
	CAboutDlg(); 
 
// Dialog Data 
	//{{AFX_DATA(CAboutDlg) 
	enum { IDD = IDD_ABOUTBOX }; 
	CHyperLink	m_email; 
	//}}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) 
	virtual BOOL OnInitDialog(); 
	//}}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) 
	DDX_Control(pDX, IDC_EMAIL, m_email); 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) 
	//{{AFX_MSG_MAP(CAboutDlg) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMosDlg dialog 
 
CMosDlg::CMosDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CMosDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CMosDlg) 
	//}}AFX_DATA_INIT 
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32 
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); 
} 
 
void CMosDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CMosDlg) 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CMosDlg, CDialog) 
	//{{AFX_MSG_MAP(CMosDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_COMMAND(ID_MENU_START, OnMenuStart) 
	ON_COMMAND(ID_MENU_ABOUT, OnMenuAbout) 
	ON_COMMAND(ID_MENU_EXIT, OnMenuExit) 
	ON_COMMAND(ID_MENU_PAUSE, OnMenuPause) 
	ON_COMMAND(ID_MENU_AGAIN, OnMenuAgain) 
	ON_COMMAND(ID_MENU_DEMO, OnMenuDemo) 
	ON_COMMAND(ID_MENU_NORMAL, OnMenuNormal) 
	ON_COMMAND(ID_MENU_DEBUG, OnMenuDebug) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CMosDlg message handlers 
 
BOOL CMosDlg::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); 
		} 
	} 
 
	SetIcon(m_hIcon, TRUE);			// Set big icon 
	SetIcon(m_hIcon, FALSE);		// Set small icon 
	CButton* pB = (CButton*)GetDlgItem(IDC_BUTTON1); 
	pB->ShowWindow(SW_HIDE); 
	m_bRUN = false; 
	m_bStart = false; 
	return TRUE; 
} 
 
BOOL CAboutDlg::OnInitDialog()  
{ 
	CDialog::OnInitDialog(); 
	 
	m_email.SetURL("mailto:biti_zx@sohu.com"); 
	m_email.SetLinkCursor(AfxGetApp()->LoadCursor(IDC_CURSOR1)); 
	CFont myFont; 
	VERIFY(myFont.CreateFont(18,0,0,0,FW_BLACK,FALSE,FALSE,0, 
							 ANSI_CHARSET,OUT_DEFAULT_PRECIS, 
							 CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY, 
							 DEFAULT_PITCH | FF_SWISS,"FF_DONTCARE")); 
	GetDlgItem(IDC_TITLE)->SetFont(&myFont); 
	return TRUE; 
} 
 
void CMosDlg::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 CMosDlg::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 CMosDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
int nMODE=0; 
UINT Mosmain(LPVOID param) 
{ 
	CInputJobDlg inputdlg; 
	Mos_main m_main; 
	CMos_sw mos_sw; 
	CMos_UI m_UI; 
	CString str1=_T(" "); 
	CString str2=_T(" "); 
	CString str3=_T(" "); 
	for(;;) 
	{ 
		if(inputdlg.DoModal()==IDOK) 
		{	 
			m_io.kb=m_io.dsk=m_io.print=NULL; 
			str1 = inputdlg.m_kbpath; 
			str2 = inputdlg.m_dskpath; 
			str3 = inputdlg.m_prtpath; 
			if(str1 == " "||str2 == " "||str3 == " ")break; 
			else{ 
					if( (m_io.kb = fopen(str1,"rt"))==NULL ){//Kb:keyboard file 
						AfxMessageBox("Error open kb file!",MB_OK|MB_ICONSTOP); 
						break; 
					} 
					if( (m_io.dsk = fopen(str2,"w+b"))==NULL ){//dsk:disk file 
						AfxMessageBox("Error open dsk file!",MB_OK|MB_ICONSTOP); 
						break; 
					} 
					if( (m_io.print = fopen(str3,"w+"))==NULL ){//print:print file 
						AfxMessageBox("Error open prt file!",MB_OK|MB_ICONSTOP); 
						break; 
					} 
			m_UI.DealWithUI(_T("Ready"),IDC_STATIC_MOS); 
			m_UI.DealWithUI(_T("Free"),IDC_STATIC_CPU); 
			}//end of else 
		}//end of if(inputdlg.DoModal()==IDOK) 
		else break; 
		m_main.init(); 
		m_UI.DealWithUI(_T("Run"),IDC_STATIC_MOS); 
		while(!m_main.term()) mos_sw.swtch(); 
		m_UI.DealWithUI(_T(" "),IDC_STATIC_CP); 
		m_UI.DealWithUI(_T("ShutDown"),IDC_STATIC_MOS); 
		m_UI.DealWithUI(_T("Free"),IDC_STATIC_CPU); 
		if( AfxMessageBox("该批作业处理完毕,是否继续提交作业?",MB_YESNO|MB_ICONQUESTION)!=IDYES ) 
			break; 
	}//end of for 
	if(m_io.kb!=NULL) 
		fclose(m_io.kb); 
	if(m_io.dsk!=NULL) 
		fclose(m_io.dsk); 
	if(m_io.print!=NULL) 
		fclose(m_io.print); 
	return 0; 
} 
 
void CMosDlg::OnMenuStart() 
{ 
	m_bRUN = true; 
	m_bStart = true; 
	pThread = AfxBeginThread(Mosmain,NULL); 
	pThread->m_bAutoDelete=false; 
} 
 
void CMosDlg::OnMenuExit() 
{ 
	SendMessage (WM_CLOSE); 
} 
 
void CMosDlg::OnMenuPause()  
{ 
	if(m_bRUN&&m_bStart) 
	{ 
		pThread->SuspendThread(); 
		m_bRUN = false; 
	} 
} 
 
void CMosDlg::OnMenuAgain()  
{ 
	if(!m_bRUN&&m_bStart) 
	{ 
		pThread->ResumeThread(); 
		m_bRUN = true; 
	} 
} 
 
void CMosDlg::OnMenuAbout()  
{ 
	CAboutDlg aboutDlg; 
	aboutDlg.DoModal(); 
} 
 
void CMosDlg::OnMenuDemo()  
{ 
	nMODE = 0; 
} 
 
void CMosDlg::OnMenuNormal()  
{ 
	nMODE = 1; 
} 
void CMosDlg::OnMenuDebug()  
{ 
	nMODE = 2; 
}