CBrush实现画矩形

网友投稿 622 2022-09-29

CBrush实现画矩形

CBrush实现画矩形

在新建的MFC单文档文件中,选择类视图,在其中选择视图类,定义一个新的点类型变量myPoint,并在视图类构造函数中初始化为零。在鼠标单击按下事件内将当前点赋给myPoint,在抬起事件中,实现画矩形。

// lessonMyBrushView.cpp : implementation of the ClessonMyBrushView class//#include "stdafx.h"// SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail// and search filter handlers and allows sharing of document code with that project.#ifndef SHARED_HANDLERS#include "lessonMyBrush.h"#endif#include "lessonMyBrushDoc.h"#include "lessonMyBrushView.h"#ifdef _DEBUG#define new DEBUG_NEW#endif// ClessonMyBrushViewIMPLEMENT_DYNCREATE(ClessonMyBrushView, CView)BEGIN_MESSAGE_MAP(ClessonMyBrushView, CView) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &ClessonMyBrushView::OnFilePrintPreview) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_WM_LBUTTONUP() ON_WM_LBUTTONDOWN()END_MESSAGE_MAP()// ClessonMyBrushView construction/destructionClessonMyBrushView::ClessonMyBrushView() : myPoint(0){ // TODO: add construction code here}ClessonMyBrushView::~ClessonMyBrushView(){}BOOL ClessonMyBrushView::PreCreateWindow(CREATESTRUCT& cs){ // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs);}// ClessonMyBrushView drawingvoid ClessonMyBrushView::OnDraw(CDC* /*pDC*/){ ClessonMyBrushDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here}// ClessonMyBrushView printingvoid ClessonMyBrushView::OnFilePrintPreview(){#ifndef SHARED_HANDLERS AFXPrintPreview(this);#endif}BOOL ClessonMyBrushView::OnPreparePrinting(CPrintInfo* pInfo){ // default preparation return DoPreparePrinting(pInfo);}void ClessonMyBrushView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){ // TODO: add extra initialization before printing}void ClessonMyBrushView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/){ // TODO: add cleanup after printing}void ClessonMyBrushView::OnRButtonUp(UINT /* nFlags */, CPoint point){ ClientToScreen(&point); OnContextMenu(this, point);}void ClessonMyBrushView::OnContextMenu(CWnd* /* pWnd */, CPoint point){#ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE);#endif}// ClessonMyBrushView diagnostics#ifdef _DEBUGvoid ClessonMyBrushView::AssertValid() const{ CView::AssertValid();}void ClessonMyBrushView::Dump(CDumpContext& dc) const{ CView::Dump(dc);}ClessonMyBrushDoc* ClessonMyBrushView::GetDocument() const // non-debug version is inline{ ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(ClessonMyBrushDoc))); return (ClessonMyBrushDoc*)m_pDocument;}#endif //_DEBUG// ClessonMyBrushView message handlersvoid ClessonMyBrushView::OnLButtonUp(UINT nFlags, CPoint point){ // TODO: Add your message handler code here and/or call default //CBitmap bitmap; CBrush brush(RGB(255,0,0)); CClientDC ccdc(this); ccdc.FillRect(CRect(myPoint,point),&brush); CView::OnLButtonUp(nFlags, point);}void ClessonMyBrushView::OnLButtonDown(UINT nFlags, CPoint point){ // TODO: Add your message handler code here and/or call default myPoint=point; CView::OnLButtonDown(nFlags, point);}

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:浅谈小程序怎么实现列表滚动上下联动效果(小程序滚动条)
下一篇:spring无法引入注解及import org.springframework.web.bind.annotation.*报错的解决
相关文章

 发表评论

暂时没有评论,来抢沙发吧~