// ChildView.cpp : implementation of the CChildView class // #include "stdafx.h" #include "FWRecipe.h" #include "MainFrm.h" #include "ChildView.h" #include ".\childview.h" #include #include using namespace std; #ifdef _DEBUG #define new DEBUG_NEW #endif // CChildView CChildView::CChildView() : m_DisplayX(100), m_DisplayY(100), m_MouseX(0), m_MouseY(0), m_TriangleX(-1), m_TriangleY(-1), m_pCStatic(NULL) { } CChildView::~CChildView() { delete m_pCStatic; } BEGIN_MESSAGE_MAP(CChildView, CWnd) ON_WM_PAINT() ON_WM_LBUTTONDOWN() ON_WM_MOUSEMOVE() ON_WM_CREATE() END_MESSAGE_MAP() // CChildView message handlers BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) { if (!CWnd::PreCreateWindow(cs)) return FALSE; cs.dwExStyle |= WS_EX_CLIENTEDGE; cs.style &= ~WS_BORDER; cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast(COLOR_WINDOW+1), NULL); return TRUE; } void CChildView::OnPaint() { CPaintDC dc(this); // device context for painting CFont font; font.CreatePointFont(200, _T("Tahoma")); dc.SelectObject(&font); dc.SetTextColor(RGB(0,0,255)); CRect rect; GetClientRect(&rect); dc.DrawText(_T("CSE775 - Distributed Objects"), -1, &rect, DT_SINGLELINE | DT_CENTER | DT_VCENTER); if(m_TriangleX >= 0) { CPen pen; pen.CreatePen(PS_SOLID,2,RGB(0,255,0)); dc.SelectObject(&pen); dc.MoveTo(m_TriangleX, m_TriangleY); dc.LineTo(m_TriangleX+50, m_TriangleY); dc.LineTo(m_TriangleX, m_TriangleY+50); dc.LineTo(m_TriangleX, m_TriangleY); } CMainFrame* pMain = (CMainFrame*)AfxGetMainWnd( ); if(pMain->getToggle()) { ostringstream temp; temp << '[' << setw(4) << m_MouseX << ", " << setw(4) << m_MouseY << ']'; dc.SetTextColor(RGB(255,25,25)); dc.TextOut(m_DisplayX,m_DisplayY,temp.str().c_str()); } } void CChildView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_TriangleX = point.x; m_TriangleY = point.y; Invalidate(); CWnd ::OnLButtonDown(nFlags, point); } void CChildView::OnMouseMove(UINT nFlags, CPoint point) { m_MouseX = point.x; m_MouseY = point.y; CWnd ::OnMouseMove(nFlags, point); CRect rect; rect.left = m_DisplayX - 2; rect.right = m_DisplayX + 200; rect.top = m_DisplayY - 2; rect.bottom = m_DisplayY + 50; InvalidateRect(&rect); ostringstream temp; temp << " " << setw(4) << m_MouseX << ", " << setw(4) << m_MouseY; CString str = temp.str().c_str(); SetDlgItemText(IDC_STATIC1,str); } int CChildView::OnCreate(LPCREATESTRUCT lpCreateStruct) { if (CWnd::OnCreate(lpCreateStruct) == -1) return -1; m_pCStatic = new CStatic(); CRect rect(CPoint(100,70),CSize(90,22)); m_pCStatic->Create("",WS_CHILD | WS_VISIBLE | WS_BORDER, rect, this, IDC_STATIC1); return 0; }