⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pcdlg.cpp

📁 有关操作系统课程设计的代码
💻 CPP
字号:
// PCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PC.h"
#include "PCDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

//##ModelId=4859530400FC
class CAboutDlg : public CDialog
{
public:
	//##ModelId=485953040109
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	//##ModelId=485953040119
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//##ModelId=485953040109
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

//##ModelId=485953040119
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()

/////////////////////////////////////////////////////////////////////////////
// CPCDlg dialog

//##ModelId=4859530303BA
CPCDlg::CPCDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPCDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPCDlg)
	m_nc = 0;
	m_np = 0;
	m_note = _T("");
	m_pnote = _T("");
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);


	m_continue=true;


	for( int i=0;i<SIZE_OF_BUFFER;i++)
	{
		m_hFullSemaphore[i]=CreateSemaphore(NULL,0,1,NULL);
		m_hEmptySemaphore[i]=CreateSemaphore(NULL,1,1,NULL);
		m_Array[i]=0;
		m_CArray[i]=0;
		m_PArray[i]=0;
		m_CStr[i]="";
		m_PStr[i]="";

	}
}

//##ModelId=48595304004E
void CPCDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPCDlg)
	DDX_Control(pDX, IDPSTAR, m_sp);
	DDX_Control(pDX, ID_STARTC, m_sc);
	DDX_Control(pDX, IDC_PMANUAL, m_pmanual);
	DDX_Control(pDX, IDC_CMANUAL, m_cmanual);
	DDX_Text(pDX, IDC_C, m_nc);
	DDX_Text(pDX, IDC_P, m_np);
	DDX_Text(pDX, IDC_NOTE, m_note);
	DDX_Text(pDX, IDC_PNOTE, m_pnote);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPCDlg, CDialog)
	//{{AFX_MSG_MAP(CPCDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_STOP, OnStop)
	ON_BN_CLICKED(IDPSTAR, OnPstar)
	ON_BN_CLICKED(ID_STARTC, OnStartc)
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_REFRESH, OnRefresh)
	ON_BN_CLICKED(IDC_CMANUAL, OnCmanual)
	ON_BN_CLICKED(IDC_PMANUAL, OnPmanual)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_EN_CHANGE(IDC_P, OnChangeP)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPCDlg message handlers

//##ModelId=48595304005D
BOOL CPCDlg::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
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

//##ModelId=48595304005F
void CPCDlg::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.

//##ModelId=48595304006F
void CPCDlg::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
	{		CBrush brush;


		brush.CreateSolidBrush( RGB(255,0,0));
		CBrush* temp;
		CPaintDC dc(this);
		temp=dc.GetCurrentBrush();
		for(int i=0; i<SIZE_OF_BUFFER;i++)
		{

			 if(m_Array[i])dc.SelectObject(&brush);
		     dc.Rectangle(20+i*40,20,20+(i+1)*40,60);
			 dc.SelectObject(temp);
			 
			 if(m_PArray[i])
			 {
				 dc.SelectObject(&brush);
				 dc.Rectangle( 30+i*40, 70, 50+i*40,90);
				 dc.TextOut( 30+i*40,90,m_PStr[i]);
				 dc.SelectObject(temp);

			 }
			 if(m_CArray[i])
			 {
				 dc.SelectObject(&brush);
				 dc.Ellipse( 30+i*40, 140, 50+i*40,160);
				 dc.TextOut( 30+i*40, 160,m_CStr[i]);
				 dc.SelectObject(temp);
			 }

		}
		brush.DeleteObject();
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
//##ModelId=48595304007D
HCURSOR CPCDlg::OnQueryDragIcon()
{
 
	return (HCURSOR) m_hIcon;
}

//##ModelId=48595304007F
void CPCDlg::OnStop() 
{
	// TODO: Add your control notification handler code here
	this->m_continue=false;
	m_sc.EnableWindow(true);
	m_sp.EnableWindow(true);
	
}

//##ModelId=485953040081
void CPCDlg::OnPstar() 
{
	// TODO: Add your control notification handler code here
    UpdateData(true);
	this->m_continue=true;
	this->SetTimer(100,1000,NULL);
	if( this->m_np>0&&this->m_np<11)
	{
		  m_sp.EnableWindow(false);
          CString str;
		  for( unsigned i=0; i<this->m_np;i++)
		  {
			str.Format("P%d",i);
			this->m_PT[i] =new CProducerThread(this,str);
			this->m_PT[i]->CreateThread(CREATE_SUSPENDED);
			VERIFY(this->m_PT[i]->SetThreadPriority(THREAD_PRIORITY_IDLE));	
			this->m_PT[i]->ResumeThread();
		  }
		  
	}
	else 
		MessageBox("生产者数目必须在1-10之间","出错了");

	
}

//##ModelId=48595304008C
void CPCDlg::OnStartc() 
{
    UpdateData(true);
    this->m_continue=true;
	if( this->m_nc>0&&this->m_nc<11)
	{
		  m_sc.EnableWindow(false);
          CString str;
		  for( unsigned i=0; i<this->m_nc;i++)
		  {
			str.Format("C%d",i);
			this->m_CT[i] =new CConsumerThread(this,str);
			this->m_CT[i]->CreateThread(CREATE_SUSPENDED);
			VERIFY(this->m_CT[i]->SetThreadPriority(THREAD_PRIORITY_IDLE));	
			this->m_CT[i]->ResumeThread();
		  }
	}
	else 
		MessageBox("消费者数目必须在1-10之间","出错了");	
}

//##ModelId=48595304008E
void CPCDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
    InvalidateRect((CRect(20,20,20+(SIZE_OF_BUFFER+1)*40,60)));
	CDialog::OnTimer(nIDEvent);
}

//##ModelId=485953040091
void CPCDlg::OnRefresh() 
{
	// TODO: Add your control notification handler code here
	m_continue=false;


	for( int i=0;i<SIZE_OF_BUFFER;i++)
	{
		m_hFullSemaphore[i]=CreateSemaphore(NULL,0,1,NULL);
		m_hEmptySemaphore[i]=CreateSemaphore(NULL,1,1,NULL);
		m_Array[i]=0;
		m_CArray[i]=0;
		m_PArray[i]=0;
		m_CStr[i]="";
		m_PStr[i]="";

	}
    Invalidate();
	m_sc.EnableWindow(true);
	m_sp.EnableWindow(true);

}

//##ModelId=48595304009C
void CPCDlg::OnCmanual() 
{

	
}

//##ModelId=48595304009E
void CPCDlg::OnPmanual() 
{




}

//##ModelId=4859530400A0
void CPCDlg::OnExit() 
{
	// TODO: Add your control notification handler code here
//	delete []m_hFullSemaphore;
//    delete []m_hEmptySemaphore;
	EndDialog(0);
	
}

//##ModelId=4859530400AB
void CPCDlg::OnChangeP() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -