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

📄 dishwasherguidlg.cpp

📁 在rhapsody下rtuml直接生成的洗碗机的程序
💻 CPP
字号:
// DishWasherGUIDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DishWasherGUI.h"
#include "DishWasherGUIDlg.h"

#include <oxf\RiC.h>
//#ifdef __cplusplus
extern "C" {
//#endif
#include "..\guilib\Default.h"
#include "..\guilib\Tank.h"
#include "..\guilib\Jet.h"
#include "..\guilib\Heater.h"
#include "..\guilib\Dishwasher.h"
//extern struct Dishwasher_t Dishwasher;
//#ifdef __cplusplus
}
//#endif


#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()

/////////////////////////////////////////////////////////////////////////////
// CDishWasherGUIDlg dialog

CDishWasherGUIDlg::CDishWasherGUIDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CDishWasherGUIDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDishWasherGUIDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CDishWasherGUIDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDishWasherGUIDlg)
	DDX_Control(pDX, IDC_SERVICE_INDICATION, m_serviceIndication);
	DDX_Control(pDX, IDC_OPER_INDICATION, m_operIndication);
	DDX_Control(pDX, IDC_OPERATION_STATES, m_OperationStatesProgress);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDishWasherGUIDlg, CDialog)
	//{{AFX_MSG_MAP(CDishWasherGUIDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_START, OnStart)
	ON_BN_CLICKED(IDC_DOOR, OnDoor)
	ON_BN_CLICKED(IDC_Intensive, OnIntensive)
	ON_BN_CLICKED(IDC_Normal, OnNormal)
	ON_BN_CLICKED(IDC_Quick, OnQuick)
	ON_WM_CTLCOLOR()
	ON_BN_CLICKED(IDC_SERVICE_BUTTON, OnServiceButton)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDishWasherGUIDlg message handlers

CBitmap doorIsClosed;
CBitmap doorIsOpenned;
UINT timerId;
COLORREF m_crOperationStateBackground;
CBrush m_operationStateBrush;
COLORREF m_crServiceBackground[2];
CBrush m_serviceBrush[2];
const int m_iOperationLastState = 5;

CString operationStates[] =
{
	"Off",
	"Filling",
	"Rinsing",
	"Washing",
	"Draining",
	"Drying"
};

CString serviceStates[] =
{
	"OK",
	"Required"
};

BOOL CDishWasherGUIDlg::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);
	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
	doorIsClosed.LoadBitmap(IDB_DOOR_CLOSED);
	doorIsOpenned.LoadBitmap(IDB_DOOR_OPENNED);
	CButton* b = (CButton*)GetDlgItem(IDC_DOOR);
	b->SetBitmap(HBITMAP(doorIsClosed));
	b = (CButton*)GetDlgItem(IDC_Normal);
	b->SetCheck(1);
	m_OperationStatesProgress.SetRange(0,m_iOperationLastState);
	m_crOperationStateBackground = RGB(255,255,0);
	m_crServiceBackground[0]     = RGB(0,255,0);
	m_crServiceBackground[1]     = RGB(255,0,0);
	m_operationStateBrush.CreateSolidBrush(m_crOperationStateBackground);
	m_serviceBrush[0].CreateSolidBrush(m_crServiceBackground[0]);
	m_serviceBrush[1].CreateSolidBrush(m_crServiceBackground[1]);
	m_operIndication.SetWindowText(operationStates[0]);
	timerId = SetTimer(1, 200, NULL);

	// define ToolTip
	m_pToolTip = new CToolTipCtrl;
	m_pToolTip->Create(this);
	m_pToolTip->AddTool(GetDlgItem(IDC_SERVICE_BUTTON), IDS_SERVICE_BUTTON);
	m_pToolTip->AddTool(GetDlgItem(IDC_START), IDS_START);
	m_pToolTip->AddTool(GetDlgItem(IDC_Normal), IDS_Normal);
	m_pToolTip->AddTool(GetDlgItem(IDC_Quick), IDS_Quick);
	m_pToolTip->AddTool(GetDlgItem(IDC_Intensive), IDS_Intensive);
	m_pToolTip->AddTool(GetDlgItem(IDC_DOOR), IDS_DOOR_OPEN);
	m_pToolTip->Activate(TRUE);
	((CDishWasherGUIApp *)AfxGetApp())->m_pToolTip = m_pToolTip;

	// Init the system	(Entry point)
	RiCOXFInit(NULL, NULL, 6423, "", 0, 0, TRUE);
    Default_OMInitializer_Init();
    RiCOXFStart(TRUE);

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDishWasherGUIDlg::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 CDishWasherGUIDlg::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 CDishWasherGUIDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CDishWasherGUIDlg::OnStart() 
{
	// TODO: Add your control notification handler code here
	//theDishwasher->GEN_BY_GUI(evStart());

    RiCGEN_BY_GUI(&Dishwasher,evStart());
	
}

CDishWasherGUIDlg::~CDishWasherGUIDlg()
{
	//delete theDishwasher;           
    Default_OMInitializer_Cleanup();

	// Win32 API function ::KillTimer user can call here,
	// but CWnd::KillTimer the user have to call in CWnd::DestroyWindow
}

void CDishWasherGUIDlg::OnDoor() 
{
	// TODO: Add your control notification handler code here
	CButton* b = (CButton*)GetDlgItem(IDC_DOOR);
	static UINT bstate = TRUE; // initially door is closed
	if (bstate)
	{
		m_pToolTip->UpdateTipText(IDS_DOOR_CLOSE, GetDlgItem(IDC_DOOR));
		b->SetBitmap(HBITMAP(doorIsOpenned));
		//theDishwasher->GEN_BY_GUI(evOpen());    
		RiCGEN_BY_GUI(&Dishwasher,evOpen());

	}
	else
	{
		m_pToolTip->UpdateTipText(IDS_DOOR_OPEN, GetDlgItem(IDC_DOOR));
		b->SetBitmap(HBITMAP(doorIsClosed));
		//theDishwasher->GEN_BY_GUI(evClose());
		RiCGEN_BY_GUI(&Dishwasher,evClose());
	}
	bstate = (!bstate);
}

void CDishWasherGUIDlg::OnIntensive() 
{
	// TODO: Add your control notification handler code here
	//theDishwasher->GEN_BY_GUI(evIntensive());
	RiCGEN_BY_GUI(&Dishwasher,evIntensive());
	
}

void CDishWasherGUIDlg::OnNormal() 
{
	// TODO: Add your control notification handler code here
	//theDishwasher->GEN_BY_GUI(evNormal());
	RiCGEN_BY_GUI(&Dishwasher,evNormal());
	
}

void CDishWasherGUIDlg::OnQuick() 
{
	// TODO: Add your control notification handler code here
	//theDishwasher->GEN_BY_GUI(evQuick());
	RiCGEN_BY_GUI(&Dishwasher,evQuick());	
}

HBRUSH CDishWasherGUIDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
{
	HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
	
	// TODO: Change any attributes of the DC here
	switch(pWnd->GetDlgCtrlID())
	{
		case IDC_OPER_INDICATION :
			pDC->SetBkColor(m_crOperationStateBackground);
			return (HBRUSH) m_operationStateBrush.GetSafeHandle();
			break;
		case IDC_SERVICE_INDICATION :
			pDC->SetBkColor(m_crServiceBackground[Dishwasher.m_iServiceState]);
			return (HBRUSH) m_serviceBrush[Dishwasher.m_iServiceState].GetSafeHandle();
			break;
	}
	
	// TODO: Return a different brush if the default is not desired
	return hbr;
}

void CDishWasherGUIDlg::OnServiceButton() 
{
	// TODO: Add your control notification handler code here
	//theDishwasher->GEN_BY_GUI(evService());
	RiCGEN_BY_GUI(&Dishwasher,evService());	
	
}

void CDishWasherGUIDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	// Display the operation state.
	m_OperationStatesProgress.SetPos(Dishwasher.m_iOperationState);
	m_operIndication.SetWindowText(operationStates[Dishwasher.m_iOperationState]);

	// Display the service state.
	CString sval;
	sval.Format("%d",Dishwasher.cycles);
	SetDlgItemText(IDC_CYCLES_VALUE, sval);
	m_serviceIndication.SetWindowText(serviceStates[Dishwasher.m_iServiceState]);
	
	CDialog::OnTimer(nIDEvent);
}

BOOL CDishWasherGUIDlg::DestroyWindow() 
{
	// TODO: Add your specialized code here and/or call the base class
	KillTimer(timerId);
	delete m_pToolTip;
	((CDishWasherGUIApp *)AfxGetApp())->m_pToolTip = NULL;
	
	return CDialog::DestroyWindow();
}

⌨️ 快捷键说明

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