Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
CalView.cpp
Package: ebd_src.zip [view]
Upload User: kelijie
Upload Date: 2007-01-01
Package Size: 123k
Code Size: 10k
Category:
Graph program
Development Platform:
Visual C++
- // CalView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "ebdlib2.h"
- #include "CalView.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CCalculatorView
- IMPLEMENT_DYNCREATE(CCalculatorView, CView)
- CCalculatorView::CCalculatorView()
- : CStandardView()
- {
- //{{AFX_DATA_INIT(CCalculatorView)
- m_iVar1 = 0;
- m_iVar2 = 0;
- //}}AFX_DATA_INIT
- m_strName = "Calculator Module";
- m_strMsg.Empty();
- IDD = ID_CALCULATOR;
- m_iOperandType = OPERAND_ADD;
- }
- CCalculatorView::~CCalculatorView()
- {
- }
- BEGIN_MESSAGE_MAP(CCalculatorView, CView)
- //{{AFX_MSG_MAP(CCalculatorView)
- ON_COMMAND(IDM_CALCULATOREXIT, OnCalculatorexit)
- ON_WM_CREATE()
- ON_BN_CLICKED(IDC_CALCULATE, OnCalculate)
- ON_COMMAND(IDM_ADD, OnAdd)
- ON_UPDATE_COMMAND_UI(IDM_ADD, OnUpdateAdd)
- ON_COMMAND(IDM_SUB, OnSub)
- ON_UPDATE_COMMAND_UI(IDM_SUB, OnUpdateSub)
- ON_COMMAND(IDM_TIME, OnTime)
- ON_UPDATE_COMMAND_UI(IDM_TIME, OnUpdateTime)
- ON_COMMAND(IDM_DVD, OnDvd)
- ON_UPDATE_COMMAND_UI(IDM_DVD, OnUpdateDvd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CCalculatorView drawing
- void CCalculatorView::OnDraw(CDC* pDC)
- {
- CCalculatorDoc* pDoc = (CCalculatorDoc*)GetDocument();
- // TODO: add draw code here
- CRect rect;
- GetClientRect(&rect);
- pDC->FillRect(&rect, &CBrush(RGB(192, 192, 192)));
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCalculatorView diagnostics
- #ifdef _DEBUG
- void CCalculatorView::AssertValid() const
- {
- CView::AssertValid();
- }
- void CCalculatorView::Dump(CDumpContext& dc) const
- {
- CView::Dump(dc);
- }
- #endif //_DEBUG
- void CCalculatorView::GetMsgFromDocument(CString msg)
- {
- m_editDocMsg->SetWindowText(msg);
- }
- /////////////////////////////////////////////////////////////////////////////
- // CCalculatorView message handlers
- void CCalculatorView::OnInitialUpdate()
- {
- CView::OnInitialUpdate();
- // TODO: Add your specialized code here and/or call the base class
- DWORD dwStaticStyle = WS_CHILD|WS_VISIBLE|SS_LEFT;
- DWORD dwEditStyle = ES_LEFT | ES_AUTOHSCROLL | WS_TABSTOP | WS_CHILD | WS_VISIBLE
- | WS_BORDER | ES_NUMBER | WS_EX_CLIENTEDGE | WS_EX_STATICEDGE;
- DWORD dwEditStyleReadOnly = ES_AUTOHSCROLL |ES_READONLY | WS_CHILD| WS_VISIBLE
- | WS_BORDER;
- DWORD dwButtonStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP |
- BS_DEFPUSHBUTTON;
- m_Font = new CFont();
- m_Font->CreateFont(-8, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
- DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
- operFont = new CFont();
- operFont->CreateFont(-16, 0, 0, 0, FW_REGULAR, FALSE, FALSE, FALSE,
- DEFAULT_CHARSET, OUT_DEFAULT_PRECIS,
- CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
- DEFAULT_PITCH | FF_DONTCARE, "MS Sans Serif");
- CRect r;
- r.SetRect(10, 9, 110+10, 14+9);
- m_txtVar1 = new CStatic();
- m_txtVar1->Create("The First Number", dwStaticStyle, r, this, IDC_STATIC1);
- m_txtVar1->SetFont(m_Font);
- r.SetRect(10, 129, 50+10, 14+129);
- m_txtOperand = new CStatic();
- m_txtOperand->Create("Operand", dwStaticStyle, r, this, IDC_STATIC2);
- m_txtOperand->SetFont(m_Font);
- r.SetRect(10, 49, 110+10, 14+49);
- m_txtVar2 = new CStatic();
- m_txtVar2->Create("The Second Number", dwStaticStyle, r, this, IDC_STATIC3);
- m_txtVar2->SetFont(m_Font);
- r.SetRect(10, 89, 50+10, 14+89);
- m_txtResult = new CStatic();
- m_txtResult->Create("Result", dwStaticStyle, r, this, IDC_STATIC4);
- m_txtResult->SetFont(m_Font);
- r.SetRect(10, 235, 200+10, 14+235);
- m_txtDocMsg = new CStatic();
- m_txtDocMsg->Create("Message from main module", dwStaticStyle, r, this, IDC_STATIC5);
- m_txtDocMsg->SetFont(m_Font);
- r.SetRect(130, 9, 210+130, 25+9);
- m_editVar1 = new CEdit();
- m_editVar1->Create(dwEditStyle, r, this, IDC_VAR1);
- m_editVar1->SetFont(m_Font);
- r.SetRect(130, 129, 120+130, 25+129);
- m_editOperand = new CEdit();
- m_editOperand->Create(dwEditStyleReadOnly, r, this, IDC_METHOD);
- m_editOperand->SetFont(operFont);
- r.SetRect(130, 49, 210+130, 25+49);
- m_editVar2 = new CEdit();
- m_editVar2->Create(dwEditStyle, r, this, IDC_VAR2);
- m_editVar2->SetFont(m_Font);
- r.SetRect(130, 89, 210+130, 25+89);
- m_editResult = new CEdit();
- m_editResult->Create(dwEditStyleReadOnly, r, this, IDC_RESULT);
- m_editResult->SetFont(m_Font);
- r.SetRect(5, 260, 530+5, 25+260);
- m_editDocMsg = new CEdit();
- m_editDocMsg->Create(dwEditStyleReadOnly, r, this, IDC_MSG);
- m_editDocMsg->SetFont(m_Font);
- r.SetRect(220, 190, 220 + 100, 190 + 30);
- m_btnCalculation = new CButton();
- m_btnCalculation->Create("&Calculation", dwButtonStyle, r, this, IDC_CALCULATE);
- m_btnCalculation->SetFont(m_Font);
- CString opeType;
- switch(m_iOperandType)
- {
- case OPERAND_ADD:
- opeType = "+";
- break;
- case OPERAND_SUB:
- opeType = "-";
- break;
- case OPERAND_MUL:
- opeType = "*";
- break;
- case OPERAND_DVD:
- opeType = "/";
- break;
- }
- m_editOperand->SetWindowText(opeType);
- }
- void CCalculatorView::OnCalculatorexit()
- {
- // TODO: Add your command handler code here
- GetParent()->SendMessage(WM_CLOSE);
- }
- int CCalculatorView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CView::OnCreate(lpCreateStruct) == -1)
- return -1;
- // TODO: Add your specialized creation code here
- return 0;
- }
- void CCalculatorView::DoDataExchange(CDataExchange* pDX)
- {
- // TODO: Add your specialized code here and/or call the base class
- CView::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CCalculatorView)
- DDX_Text(pDX, IDC_VAR1, m_iVar1);
- DDV_MinMaxInt(pDX, m_iVar1, -32768, 32768);
- DDX_Text(pDX, IDC_VAR2, m_iVar2);
- DDV_MinMaxInt(pDX, m_iVar2, -32768, 32768);
- //}}AFX_DATA_MAP
- }
- void CCalculatorView::OnCalculate()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- int result;
- CString opertype;
- switch(m_iOperandType)
- {
- case OPERAND_ADD:
- result = m_iVar1 + m_iVar2;
- opertype = " + ";
- break;
- case OPERAND_SUB:
- result = m_iVar1 - m_iVar2;
- opertype = " - ";
- break;
- case OPERAND_MUL:
- result = m_iVar1 * m_iVar2;
- opertype = " * ";
- break;
- case OPERAND_DVD:
- if(m_iVar2 == 0)
- {
- this->MessageBox("The divider is zero !", "Calculator", MB_OK);
- return;
- }
- else
- result = m_iVar1 / m_iVar2;
- opertype = " / ";
- break;
- }
- char str[40];
- itoa(result, str, 10);
- m_editResult->SetWindowText(str);
- CString msg;
- itoa(m_iVar1, str, 10);
- msg = str;
- msg += opertype;
- itoa(m_iVar2, str, 10);
- msg += str;
- msg += " = ";
- itoa(result, str, 10);
- msg += str;;
- GetDocument()->GetMsgFromView(IDD, m_iPin, msg);
- }
- void CCalculatorView::OnAdd()
- {
- // TODO: Add your command handler code here
- m_iOperandType = OPERAND_ADD;
- CString opeType;
- opeType = " + ";
- m_editOperand->SetWindowText(opeType);
- }
- void CCalculatorView::OnUpdateAdd(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_iOperandType == OPERAND_ADD);
- }
- void CCalculatorView::OnSub()
- {
- // TODO: Add your command handler code here
- m_iOperandType = OPERAND_SUB;
- CString opeType;
- opeType = " - ";
- m_editOperand->SetWindowText(opeType);
- }
- void CCalculatorView::OnUpdateSub(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_iOperandType == OPERAND_SUB);
- }
- void CCalculatorView::OnTime()
- {
- // TODO: Add your command handler code here
- m_iOperandType = OPERAND_MUL;
- CString opeType;
- opeType = " * ";
- m_editOperand->SetWindowText(opeType);
- }
- void CCalculatorView::OnUpdateTime(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_iOperandType == OPERAND_MUL);
- }
- void CCalculatorView::OnDvd()
- {
- // TODO: Add your command handler code here
- m_iOperandType = OPERAND_DVD;
- CString opeType;
- opeType = " / ";
- m_editOperand->SetWindowText(opeType);
- }
- void CCalculatorView::OnUpdateDvd(CCmdUI* pCmdUI)
- {
- // TODO: Add your command update UI handler code here
- pCmdUI->SetCheck(m_iOperandType == OPERAND_DVD);
- }
- void CCalculatorView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
- {
- // TODO: Add your specialized code here and/or call the base class
- if(pHint == NULL)
- return;
- CString msg;
- WNDINFO* info = (WNDINFO *)pHint;
- if(info->m_iID == (int)IDD && info->m_iPin == m_iPin)
- {
- if((int)lHint == UPDATE_ONE)
- {
- msg = "This system information is broadvasted to me!";
- CCalDlg dlg(this);
- dlg.SetOperand(m_iOperandType);
- if(dlg.DoModal())
- {
- dlg.GetOperand(&m_iOperandType);
- CString opeType;
- switch(m_iOperandType)
- {
- case OPERAND_ADD:
- opeType = " + ";
- break;
- case OPERAND_SUB:
- opeType = " - ";
- break;
- case OPERAND_MUL:
- opeType = " * ";
- break;
- case OPERAND_DVD:
- opeType = " / ";
- break;
- }
- m_editOperand->SetWindowText(opeType);
- }
- }
- else
- msg = "This system information doesn't have any thing with me!";
- }
- else
- msg = "This system information doesn't have any thing with me!";
- m_editDocMsg->SetWindowText(msg);
- }