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

📄 mywinmenuview.cpp

📁 vc环境编写的源码
💻 CPP
字号:
// MyWinMenuView.cpp : implementation of the CMyWinMenuView class
//

#include "stdafx.h"
#include "MyWinMenu.h"

#include "MyWinMenuDoc.h"
#include "MyWinMenuView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView

IMPLEMENT_DYNCREATE(CMyWinMenuView, CView)

BEGIN_MESSAGE_MAP(CMyWinMenuView, CView)
	//{{AFX_MSG_MAP(CMyWinMenuView)
	ON_COMMAND(ID_LINE, OnLine)
	ON_COMMAND(ID_ELLIPSE, OnEllipse)
	ON_UPDATE_COMMAND_UI(ID_ELLIPSE, OnUpdateEllipse)
	ON_UPDATE_COMMAND_UI(ID_LINE, OnUpdateLine)
	ON_COMMAND(ID_RECTANGLE, OnRectangle)
	ON_UPDATE_COMMAND_UI(ID_RECTANGLE, OnUpdateRectangle)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONUP()
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
	ON_UPDATE_COMMAND_UI(ID_Y,OnUpdateY)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView construction/destruction

CMyWinMenuView::CMyWinMenuView()
{
	// TODO: add construction code here
	m_MouseDown=0;
	m_Shape=1;
	ptr_myPrePen=new CPen(0,0,RGB(255,255,255));
	m_Mousex=0;
	m_Mousey=0;


}

CMyWinMenuView::~CMyWinMenuView()
{
	delete ptr_myPrePen;
}

BOOL CMyWinMenuView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView drawing

void CMyWinMenuView::OnDraw(CDC* pDC)
{
	CMyWinMenuDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView printing

BOOL CMyWinMenuView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CMyWinMenuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CMyWinMenuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView diagnostics

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

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

CMyWinMenuDoc* CMyWinMenuView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMyWinMenuDoc)));
	return (CMyWinMenuDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CMyWinMenuView message handlers

void CMyWinMenuView::OnLine() 
{
	// TODO: Add your command handler code here
	m_Shape=1;
	
}

void CMyWinMenuView::OnEllipse() 
{
	// TODO: Add your command handler code here
		m_Shape=3;
	
	
}

void CMyWinMenuView::OnUpdateEllipse(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(m_Shape==3?1:0);
	
}

void CMyWinMenuView::OnUpdateLine(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
	pCmdUI->SetCheck(m_Shape==1?1:0);
	
}

void CMyWinMenuView::OnRectangle() 
{
	// TODO: Add your command handler code here
		m_Shape=2;
	
	
}

void CMyWinMenuView::OnUpdateRectangle(CCmdUI* pCmdUI) 
{
	// TODO: Add your command update UI handler code here
		pCmdUI->SetCheck(m_Shape==2?1:0);
}

void CMyWinMenuView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_LineEnd=m_LineOrg=point;
	m_MouseDown=1;
	CView::OnLButtonDown(nFlags, point);
}

void CMyWinMenuView::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(m_MouseDown)
	{
		CClientDC DC(this);
		ptr_myDefPen=DC.SelectObject(ptr_myPrePen);
		DC.SetROP2(R2_XORPEN);
		DC.MoveTo(m_LineOrg);
		switch(m_Shape)
		{
         case 1:
		        DC.LineTo(m_LineEnd);
				DC.MoveTo(m_LineOrg);
				m_LineEnd=point;
				DC.LineTo(m_LineEnd);
				break;
         case 2:
				DC.SelectStockObject(HOLLOW_BRUSH);
				DC.Rectangle(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
				DC.MoveTo(m_LineOrg);
				m_LineEnd=point;
				DC.Rectangle(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
				break;
         case 3:
                DC.SelectStockObject(NULL_BRUSH);
				DC.Ellipse(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
				DC.MoveTo(m_LineOrg);
				m_LineEnd=point;
				DC.Ellipse(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
				break;	
					
		}

	}
	m_Mousex=point.x;
	m_Mousey=point.y;
		
	CView::OnMouseMove(nFlags, point);
}

void CMyWinMenuView::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_MouseDown=0;
	CClientDC DC(this);
	ptr_myDefPen=DC.SelectObject(ptr_myPrePen);
    DC.SetROP2(R2_XORPEN);
	DC.MoveTo(m_LineOrg);
	switch(m_Shape)
	{
      case1:
	        DC.LineTo(m_LineEnd);
			DC.MoveTo(m_LineOrg);
			m_LineEnd=point;
			DC.LineTo(m_LineOrg);
			break;
      case2:
            DC.SelectStockObject(HOLLOW_BRUSH);
			DC.Rectangle(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
			DC.MoveTo(m_LineOrg);
			m_LineEnd=point;
			DC.Rectangle(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
			break;
     case3:
			DC.SelectStockObject(NULL_BRUSH);
			DC.Ellipse(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
			DC.MoveTo(m_LineOrg);
			m_LineEnd=point;
			DC.Ellipse(m_LineOrg.x,m_LineOrg.y,m_LineEnd.x,m_LineEnd.y);
			break;
	}
	
	CView::OnLButtonUp(nFlags, point);
}

//DEL void CMyWinMenuView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint) 
//DEL {
//DEL 	// TODO: Add your specialized code here and/or call the base class
//DEL 	
//DEL 	
//DEL }

 void CMyWinMenuView::OnUpdateX(CCmdUI *pCmdUI)
 {
	 CString prompt;
	 pCmdUI->Enable();
	 prompt.Format("X:%d",m_Mousex);
	 pCmdUI->SetText(prompt);

 }
void CMyWinMenuView::OnUpdateY(CCmdUI *pCmdUI)
 {
	 CString prompt;
	 pCmdUI->Enable();
	 prompt.Format("Y:%d",m_Mousey);
	 pCmdUI->SetText(prompt);

 }

⌨️ 快捷键说明

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