// DrawView.cpp : CDrawView 类的实现
//

#include "stdafx.h"
#include "Draw.h"

#include "DrawDoc.h"
#include "DrawView.h"
#include "2DObject.h"
#include "DlgDBConnect.h"
#include "DlgDataManage.h"
#include "DlgSettings.h"
#include "DlgDataUpload.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif


// CDrawView

IMPLEMENT_DYNCREATE(CDrawView, CView)

BEGIN_MESSAGE_MAP(CDrawView, CView)
	// 标准打印命令
	ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, &CView::OnFilePrintPreview)
	ON_COMMAND_RANGE(_ID_DRAW_BEGIN, _ID_DRAW_END, &CDrawView::OnCmdMenuDraw)
	ON_UPDATE_COMMAND_UI_RANGE(_ID_DRAW_BEGIN, _ID_DRAW_END, &CDrawView::OnUpdateCmdMenuDraw)
	ON_COMMAND_RANGE(_ID_DB_BEGIN,_ID_DB_END, &CDrawView::OnCmdMenuDB)
	ON_UPDATE_COMMAND_UI_RANGE(_ID_DB_BEGIN,_ID_DB_END, &CDrawView::OnUpdateCmdMenuDB)
	ON_COMMAND_RANGE(_ID_POP_POLY_BEGIN,_ID_POP_POLY_END, &CDrawView::OnCmdMenuPolyLinePopup)
	ON_COMMAND_RANGE(_ID_POP_CURVE_BEGIN,_ID_POP_CURVE_END, &CDrawView::OnCmdMenuCurvePopup)
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_WM_MOUSEMOVE()
	ON_WM_RBUTTONUP()
	ON_WM_SETCURSOR()
END_MESSAGE_MAP()

// CDrawView 构造/析构

CDrawView::CDrawView()
{
	// TODO: 在此处添加构造代码
    m_bStatus = FALSE;
	m_ptMove = CPoint(0,0);
	m_ptEnd  = CPoint(0,0);
	m_MouseStatus = MOUSENULL;
}

CDrawView::~CDrawView()
{
}

BOOL CDrawView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: 在此处通过修改
	//  CREATESTRUCT cs 来修改窗口类或样式

	return CView::PreCreateWindow(cs);
}

// CDrawView 绘制

void CDrawView::OnDraw(CDC* pDC)
{
	CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (!pDoc)
		return;

	// TODO: 在此处为本机数据添加绘制代码

	if (pDoc->m_DrawType == DRAW_CURVE && m_bStatus)
	{
		DrawCurve(pDC);
		if (g_2DObj.m_bHide)
			return;
	}
	pDoc->m_pMap->Draw(pDC);
}


// CDrawView 打印

BOOL CDrawView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// 默认准备
	return DoPreparePrinting(pInfo);
}

void CDrawView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加额外的打印前进行的初始化过程
}

void CDrawView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: 添加打印后进行的清除过程
}


// CDrawView 诊断

#ifdef _DEBUG
void CDrawView::AssertValid() const
{
	CView::AssertValid();
}

void CDrawView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDrawDoc* CDrawView::GetDocument() const // 非调试版本是内联的
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDrawDoc)));
	return (CDrawDoc*)m_pDocument;
}
#endif //_DEBUG

void CDrawView::OnCmdMenuDraw( UINT nMenuID )
{
	CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	if (m_bStatus && pDoc->m_arPt.GetCount() != 0)
	{
		AfxMessageBox(_T("请先结束当前画图操作，再选择画图类型！"));
        return;
	}
	switch(nMenuID)
	{
	case ID_DRAW_POINT:
		{
			pDoc->m_DrawType = DRAW_POINT;
		}
		break;
	case ID_DRAW_LINE:
		{
			pDoc->m_DrawType = DRAW_BEELINE;
		}
		break;
	case ID_DRAW_POLYLINE:
		{
			pDoc->m_DrawType = DRAW_POLYLINE;
		}
	    break;
	case ID_DRAW_CURVE:
		{
			pDoc->m_DrawType = DRAW_CURVE;
		}
		break;
	case ID_DRAW_TRIANGLE:
		{
			pDoc->m_DrawType = DRAW_TRIANGLE;
		}
		break;
	case ID_DRAW_CIRCLE:
		{
			pDoc->m_DrawType = DRAW_CIRCLE;
		}
		break;
	case ID_DRAW_SETTINGS:
		{
			CDlgSettings dlg;
			dlg.DoModal();
		}
	default:
		TRACE("Error nMenuID:%ld In CDrawView::OnCmdMenuDraw!\n",nMenuID);
	}
}




// CDrawView 消息处理程序

void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
    m_MouseStatus = LBUTTONDOWM;
	CView::OnLButtonDown(nFlags, point);
}

void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	m_MouseStatus = LBUTTONUP;
    CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CClientDC dc(this);
	switch(pDoc->m_DrawType)
	{
	case DRAW_POINT:
		{
			C2DPoint* pObj = new C2DPoint(point);
			pDoc->m_pMap->AddObject(pObj);
			pDoc->SetModifiedFlag(TRUE);
			Invalidate(TRUE);
		}
		break;
	case DRAW_BEELINE:
		{
			CClientDC dc(this);
			if (!m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.Add(CPoint(point));
                dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			}
			else
			{
				m_bStatus = !m_bStatus;
				if (pDoc->m_arPt.GetCount() != 0)
				{
					C2DBeeLine* pObj = new C2DBeeLine(pDoc->m_arPt.GetAt(0), point);
					pDoc->m_pMap->AddObject(pObj);
					pDoc->m_arPt.RemoveAll();                   
					m_ptEnd = CPoint(0,0);
					pDoc->SetModifiedFlag(TRUE);
					Invalidate(TRUE);
				}
			}
		}
		break;
	case DRAW_POLYLINE:
		{
			CClientDC dc(this);
			if (!m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.Add(point);
				dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			} 
			else
			{
				pDoc->m_arPt.Add(point);
				dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			}
		}
		break;
	case DRAW_CURVE:
		{
			CClientDC dc(this);
			if (!m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.Add(point);
				//dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			} 
			else
			{
				pDoc->m_arPt.Add(point);
				//dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			}
		}
		break;
	case DRAW_TRIANGLE:
		{
			CClientDC dc(this);
			if (!m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.Add(point);
                dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
			}
			else
			{	
				pDoc->m_arPt.Add(point);
				int nCount = (int)pDoc->m_arPt.GetCount();
				dc.Ellipse(point.x-3,point.y-3,point.x+3,point.y+3);
				if (nCount == 3)
				{
					m_bStatus = !m_bStatus;
					C2DTriangle* pObj = new C2DTriangle(pDoc->m_arPt);
					pDoc->m_pMap->AddObject(pObj);
					pDoc->m_arPt.RemoveAll();
					m_ptEnd = CPoint(0,0);
					pDoc->SetModifiedFlag(TRUE);
					Invalidate(TRUE);
				}
			}
		}
		break;
	case DRAW_CIRCLE:
		{
            CClientDC dc(this);
			if (!m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.Add(point);
				CBrush br(RGB(0,0,0));
				CBrush* pOldBr = dc.SelectObject(&br);
				dc.Ellipse(point.x-2,point.y-2,point.x+2,point.y+2);
				dc.SelectObject(pOldBr);
			}
			else
			{
				m_bStatus = !m_bStatus;
				CPoint pt = pDoc->m_arPt.GetAt(0);
				CPoint ptl,ptr;
				DWORD dw = GetLengthFromTwoPoints(pt,point);;
				ptl = CPoint(pt.x-dw,pt.y-dw);
				ptr = CPoint(pt.x+dw,pt.y+dw);
				C2DCircle* pObj = new C2DCircle(ptl,ptr);
				pDoc->m_pMap->AddObject(pObj);
				pDoc->m_arPt.RemoveAll();
				m_ptEnd = CPoint(0,0);
				pDoc->SetModifiedFlag(TRUE);
				Invalidate(TRUE);
			}
		}
	default:
		;
	}

	CView::OnLButtonUp(nFlags, point);
}

void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	m_MouseStatus = MOUSEMOVE;
    CClientDC dc(this);
	CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	switch(pDoc->m_DrawType)
	{
	case DRAW_POINT:
		break;
	case DRAW_BEELINE:
		{
			if (m_bStatus)
			{
				dc.SetROP2(R2_NOTXORPEN);
				CPoint ptS = pDoc->m_arPt.GetAt(0);
				if (m_ptEnd != CPoint(0,0))
				{
					dc.MoveTo(ptS);
					dc.LineTo(m_ptEnd);
				}
				m_ptEnd = point;
				dc.MoveTo(ptS);
				dc.LineTo(m_ptEnd);
			}
		}
		break;
	case DRAW_POLYLINE:
		{
			if (m_bStatus)
			{
				dc.SetROP2(R2_NOTXORPEN);
				CPoint ptS = pDoc->m_arPt.GetAt(pDoc->m_arPt.GetCount()-1);
				if (m_ptEnd != CPoint(0,0))
				{
					dc.MoveTo(ptS);
					dc.LineTo(m_ptEnd);
				}

				m_ptEnd = point;
				dc.MoveTo(ptS);
				dc.LineTo(m_ptEnd);
			}
		}
		break;
	case DRAW_CURVE:
		{
			// 曲线采用实时绘制的方式生成橡皮线与实时曲线，与折线方法不同
			if (m_bStatus)
			{
				switch(g_2DObj.m_CurveType)
				{
				case CURVE_BEZIER:
					{
//  						m_ptMove = point;
//  						m_ptEnd = point;
// 
// 						dc.SetROP2(R2_NOTXORPEN);
// 						CPoint ptS = pDoc->m_arPt.GetAt(pDoc->m_arPt.GetCount()-1);
// 						if (m_ptEnd != CPoint(0,0))
// 						{
// 							dc.MoveTo(ptS);
// 							dc.LineTo(m_ptEnd);
// 							DrawCurve(&dc);
// 						}
// 
// 						m_ptEnd = point;
// 						dc.MoveTo(ptS);
// 						dc.LineTo(m_ptEnd);
// 						DrawCurve(&dc);
						m_ptMove = point;
						m_ptEnd  = point;
						Invalidate(TRUE);
					}
					break;
				default:
					;
				}
			}
		}
		break;
	case DRAW_TRIANGLE:
		{
			if (m_bStatus)
			{
				int nCount = (int)pDoc->m_arPt.GetCount();				
				if (nCount == 1)
				{
					dc.SetROP2(R2_NOTXORPEN);
					CPoint ptS = pDoc->m_arPt.GetAt(0);
					if (m_ptEnd != CPoint(0,0))
					{
						dc.MoveTo(ptS);
						dc.LineTo(m_ptEnd);
					}

					m_ptEnd = point;
					dc.MoveTo(ptS);
					dc.LineTo(m_ptEnd);
				}
				else if (nCount == 2)
				{
					CPoint pt0 = pDoc->m_arPt.GetAt(0);
					CPoint pt1 = pDoc->m_arPt.GetAt(1);
					dc.MoveTo(pt0);
					dc.LineTo(pt1);
					dc.SetROP2(R2_NOTXORPEN);
					if (m_ptEnd != CPoint(0,0))
					{

						dc.MoveTo(pt0);
						dc.LineTo(m_ptEnd);
						dc.MoveTo(pt1);
                        dc.LineTo(m_ptEnd);
					}
					m_ptEnd = point;
					dc.MoveTo(pt0);
					dc.LineTo(m_ptEnd);
					dc.MoveTo(pt1);
					dc.LineTo(m_ptEnd);
				}				
			}
		}
		break;
	case DRAW_CIRCLE:
		{
			if (m_bStatus)
			{
				dc.SetROP2(R2_NOTXORPEN);
				CPoint ptS = pDoc->m_arPt.GetAt(0);
				if (m_ptEnd != CPoint(0,0))
				{
					DWORD dw = GetLengthFromTwoPoints(ptS,m_ptEnd);
					CRect rt(ptS.x-dw,ptS.y-dw,ptS.x+dw,ptS.y+dw);
					dc.Ellipse(rt);
				}

				m_ptEnd = point;
				DWORD dw = GetLengthFromTwoPoints(ptS,m_ptEnd);
				CRect rt(ptS.x-dw,ptS.y-dw,ptS.x+dw,ptS.y+dw);
				dc.Ellipse(rt);
			}
		}
		break;
	default:
		;
	}

	CView::OnMouseMove(nFlags, point);
}

void CDrawView::OnRButtonUp(UINT nFlags, CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	m_MouseStatus = RBUTTONUP;
	CDrawDoc* pDoc = GetDocument();

	switch(pDoc->m_DrawType)
	{
	case DRAW_POLYLINE:
		{
			if (m_bStatus)
			{
				PopupMenu(IDR_MENU_EDIT_POLYLINE);
			}
		}
		break;
	case DRAW_CURVE:
		{
			if (m_bStatus)
			{
				PopupMenu(IDR_MENU_EDIT_CURVE);
			}
		}
		break;
	default:
		;
	}

	CView::OnRButtonUp(nFlags, point);
}

void CDrawView::PopupMenu( UINT nMenuID )
{
	CMenu popMenu;
	popMenu.LoadMenu(nMenuID);
	CPoint posMouse;
	GetCursorPos(&posMouse);
	popMenu.GetSubMenu(0)->TrackPopupMenu(0,posMouse.x,posMouse.y,this->GetParent());
}

void CDrawView::OnCmdMenuPolyLinePopup( UINT nMenuID )
{
	CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	switch(nMenuID)
	{
	case IDM_EDIT_POLYLINE_REPEAL:
		{
			if (m_bStatus)
			{
				CClientDC dc(this);
                int nCount = (int)pDoc->m_arPt.GetCount();
				if (nCount>1)
				{
					CPoint pt1,pt2;
					pt1 = pDoc->m_arPt.GetAt(nCount-2);
					pt2 = pDoc->m_arPt.GetAt(nCount-1);
					pDoc->m_arPt.RemoveAt(nCount-1);
					dc.SetROP2(R2_NOTXORPEN);
					dc.MoveTo(pt1);
					dc.LineTo(pt2);
					dc.MoveTo(pt2);
					dc.LineTo(m_ptEnd);					
					dc.MoveTo(pt1);
					dc.LineTo(m_ptEnd);
					dc.SetROP2(R2_WHITE);
					dc.Ellipse(pt2.x-3,pt2.y-3,pt2.x+3,pt2.y+3);
				}
			}
		}
		break;
	case IDM_EDIT_POLYLINE_OK:
		{
			if (m_bStatus)
			{
				m_bStatus = !m_bStatus;
				if (pDoc->m_arPt.GetCount() != 0)
				{
					pDoc->m_arPt.Add(m_ptEnd);
					C2DPolyLine* pObj = new C2DPolyLine(pDoc->m_arPt);
					pDoc->m_pMap->AddObject(pObj);
					pDoc->m_arPt.RemoveAll();
					pDoc->m_arPt.FreeExtra();
					m_ptEnd = CPoint(0,0);
					Invalidate(TRUE);
					pDoc->SetModifiedFlag(TRUE);
				}
			}
		}
		break;
	case IDM_EDIT_POLYLINE_EXIT:
		{
			if (m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.FreeExtra();
				m_ptEnd = CPoint(0,0);
				Invalidate(TRUE);
			}		
		}
		break;
	case IDM_EDIT_POLYLINE_CANCEL:
		{
		}
		break;
	default:
		TRACE("Error nMenuID:%ld In CDrawView::OnCmdMenuPolyLinePopup!\n",nMenuID);
	}
}

void CDrawView::OnCmdMenuCurvePopup( UINT nMenuID )
{
	CDrawDoc* pDoc = GetDocument();
	switch(nMenuID)
	{
	case IDM_EDIT_CURVE_REPEAL:
		{
			if (m_bStatus)
			{
				CClientDC dc(this);
				int nCount = (int)pDoc->m_arPt.GetCount();
				if (nCount>1)
				{
					pDoc->m_arPt.RemoveAt(nCount-1);
				}
			}
		}
		break;
	case IDM_EDIT_CURVE_OK:
		{
			if (m_bStatus)
			{
				if (pDoc->m_arPt.GetCount()>0)
				{
					pDoc->m_arPt.Add(m_ptEnd);
					C2DCurve* pObj = new C2DCurve(pDoc->m_arPt, (enumCurveType)g_2DObj.m_CurveType);
					pDoc->m_pMap->AddObject(pObj);
					m_bStatus = !m_bStatus;
					pDoc->m_arPt.RemoveAll();
					pDoc->m_arPt.FreeExtra();
					m_ptEnd = CPoint(0,0);
					pDoc->SetModifiedFlag(TRUE);
					Invalidate(TRUE);
				}
			}
		}
		break;
	case IDM_EDIT_CURVE_EXIT:
		{
			if (m_bStatus)
			{
				m_bStatus = !m_bStatus;
				pDoc->m_arPt.RemoveAll();
				pDoc->m_arPt.FreeExtra();
				m_ptEnd = CPoint(0,0);
				Invalidate(TRUE);
			}
		}
		break;
	case IDM_EDIT_PCURVE_CANCEL:
		{
		}
		break;
	default:
		TRACE("Error nMenuID:%ld in CDrawView::OnCmdMenuCurvePopup!\n",nMenuID);
	}
}

void CDrawView::OnCmdMenuDB( UINT nMenuID )
{
	CDrawDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	switch(nMenuID)
	{
	case ID_DB_CONNECT:
		{
			CDlgDBConnect dlg;
			dlg.m_pConnection = g_pConnection;
			dlg.DoModal();
			g_pConnection = dlg.m_pConnection;
		}
		break;
	case ID_DB_MANAGE:
		{
			CDlgDataManage dlg;
			dlg.m_pMap = pDoc->m_pMap;
			if (dlg.DoModal() == IDOK)
			{
				pDoc->m_pMap = dlg.m_pMap;
				Invalidate(TRUE);
			}			
// 			CDBOperate db;
// 			db.m_pConnection = g_pConnection;
// 			C2DMap* pMap = db.CreateMap(_T("1"));
// 			if (pMap)
// 			{
// 				C2DMap* pOrgMap = pDoc->m_pMap;
// 				delete pOrgMap;
// 				pDoc->m_pMap = pMap;
// 				Invalidate(TRUE);
// 			}
		}
		break;
	case ID_DB_UP:
		{
			CDlgDataUpload dlg;
			dlg.m_pMap = pDoc->m_pMap;
			dlg.DoModal();
		}
		break;
	default:
		TRACE("Error nMenuID:%ld in CDrawView::OnCmdMenuDB!\n",nMenuID);
	}
}

void CDrawView::OnUpdateCmdMenuDB( CCmdUI* pCmdUI )
{
	UINT nMenuID = pCmdUI->m_nID;
	switch(nMenuID)
	{
	case IDC_BTN_CONNECT:
		{

		}
		break;
	case ID_DB_MANAGE:
		{
			if (g_pConnection)
			{
				if (!(g_pConnection->GetState() != adStateClosed))
				{
					pCmdUI->Enable(FALSE);
				}
			}
			else
			{
				pCmdUI->Enable(FALSE);
			}
		}
		break;
	case ID_DB_UP:
		{
			if (g_pConnection)
			{
				if (!(g_pConnection->GetState() != adStateClosed))
				{
					pCmdUI->Enable(FALSE);
				}
			}
			else
			{
				pCmdUI->Enable(FALSE);
			}
		}
		break;
	default:
		TRACE("Error nMenuID:%ld in CDrawView::OnUpdateCmdMenuDB!\n",nMenuID);
	}
}

void CDrawView::DrawCurve( CDC* pDC )
{
    CDrawDoc* pDoc = GetDocument();
	switch(g_2DObj.m_CurveType)
	{
	case CURVE_BEZIER:
		{
			int nCount = (int)pDoc->m_arPt.GetCount();			
			if (nCount>0)
			{
				if (m_MouseStatus == MOUSEMOVE)
				{
					pDoc->m_arPt.Add(m_ptMove);
					nCount = (int)pDoc->m_arPt.GetCount();
				}

				// 画参照线
				CPoint pt;
				pt = pDoc->m_arPt.GetAt(0);
				pDC->MoveTo(pt);
				pDC->Ellipse(pt.x-3,pt.y-3,pt.x+3,pt.y+3);
				for (int i=1; i!=nCount; ++i)
				{
					pt = pDoc->m_arPt.GetAt(i);
					pDC->LineTo(pt);
					pDC->Ellipse(pt.x-3,pt.y-3,pt.x+3,pt.y+3);
				}

				// 画曲线
				pDC->MoveTo(pDoc->m_arPt.GetAt(0));
				double t,x,y;
				for (t=0; t<=1; t+=0.001)
				{
					x = 0;
					y = 0;
					for (int i=0; i!=nCount; ++i)
					{
						x += Combination(nCount-1,i)*Power(t,i)*Power((1-t),(nCount-1-i))*pDoc->m_arPt.GetAt(i).x;
						y += Combination(nCount-1,i)*Power(t,i)*Power((1-t),(nCount-1-i))*pDoc->m_arPt.GetAt(i).y;
					}
					pDC->LineTo((int)x,(int)y);
				}

				if (m_MouseStatus == MOUSEMOVE)
				{
					pDoc->m_arPt.RemoveAt(nCount-1);
				}
			}
		}
		break;
	default:
		;
	}
}



BOOL CDrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	CDrawDoc* pDoc = GetDocument();
	
/*
	switch(pDoc->m_DrawType)
	{
	case DRAW_POINT:
	case DRAW_BEELINE:
	case DRAW_POLYLINE:
	case DRAW_CURVE:
	case DRAW_TRIANGLE:
	case DRAW_CIRCLE:
		{
			//SetCursor(AfxGetApp()->LoadCursor(IDC_CROSS));
			AfxGetApp()->LoadStandardCursor(IDC_CROSS);
		}
		break;
	default:
		//SetCursor(AfxGetApp()->LoadCursor(IDC_ARROW));
		AfxGetApp()->LoadStandardCursor(IDC_ARROW);
	}*/

// 	AfxGetApp()->LoadStandardCursor(IDC_CROSS);
// 	::ShowCursor(TRUE);

	return CView::OnSetCursor(pWnd, nHitTest, message);
}

void CDrawView::OnUpdateCmdMenuDraw( CCmdUI* pCmdUI )
{
	CDrawDoc* pDoc = GetDocument();
	switch(pDoc->m_DrawType)
	{
	case DRAW_POINT:
		{
			if (pCmdUI->m_nID == ID_DRAW_POINT)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	case DRAW_BEELINE:
		{
			if (pCmdUI->m_nID == ID_DRAW_LINE)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	case DRAW_POLYLINE:
		{
			if (pCmdUI->m_nID == ID_DRAW_POLYLINE)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	case DRAW_CURVE:
		{
			if (pCmdUI->m_nID == ID_DRAW_CURVE)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	case DRAW_TRIANGLE:
		{
			if (pCmdUI->m_nID == ID_DRAW_TRIANGLE)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	case DRAW_CIRCLE:
		{
			if (pCmdUI->m_nID == ID_DRAW_CIRCLE)
			{
				pCmdUI->SetCheck(TRUE);
			}
			else
			{
				pCmdUI->SetCheck(FALSE);
			}
		}
		break;
	default:
		;
	}
}
