www.pudn.com > PC_final.rar > PCDlg.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;iAppendMenu(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; im_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; im_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; im_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