📄 ch6demo1view.cpp
字号:
// Ch6Demo1View.cpp : implementation of the CCh6Demo1View class
//
#include "stdafx.h"
#include "Ch6Demo1.h"
#include "Ch6Demo1Doc.h"
#include "Ch6Demo1View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View
IMPLEMENT_DYNCREATE(CCh6Demo1View, CView)
BEGIN_MESSAGE_MAP(CCh6Demo1View, CView)
//{{AFX_MSG_MAP(CCh6Demo1View)
ON_COMMAND(ID_DRAWCIRCLE, OnDrawcircle)
ON_COMMAND(ID_DRAWRECT, OnDrawrect)
ON_UPDATE_COMMAND_UI(ID_DRAWCIRCLE, OnUpdateDrawcircle)
ON_UPDATE_COMMAND_UI(ID_DRAWRECT, OnUpdateDrawrect)
ON_WM_RBUTTONDOWN()
//}}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)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View construction/destruction
CCh6Demo1View::CCh6Demo1View()
{
// TODO: add construction code here
m_nDdrawtype=0;
}
CCh6Demo1View::~CCh6Demo1View()
{
}
BOOL CCh6Demo1View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View drawing
void CCh6Demo1View::OnDraw(CDC* pDC)
{
CCh6Demo1Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View printing
BOOL CCh6Demo1View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CCh6Demo1View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CCh6Demo1View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View diagnostics
#ifdef _DEBUG
void CCh6Demo1View::AssertValid() const
{
CView::AssertValid();
}
void CCh6Demo1View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CCh6Demo1Doc* CCh6Demo1View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCh6Demo1Doc)));
return (CCh6Demo1Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CCh6Demo1View message handlers
void CCh6Demo1View::OnDrawcircle()
{
// TODO: Add your command handler code here
m_nDdrawtype=1;//表示绘制圆
CDC*pDC=GetDC(); //使用GetDC()函数申请CDC类的指针
CRect rect(100,0,320,200);
CBrush brush(RGB(180,180,180));//定义画刷
pDC->FillRect(rect,&brush);//填充绘图区域
pDC->Ellipse(160,10,260,110); //画圆
pDC->TextOut(120,120,"绘制直径为100个像素的圆");//在圆下方输出文字
ReleaseDC(pDC); //释放CDC类的指针
}
void CCh6Demo1View::OnDrawrect()
{
// TODO: Add your command handler code here
m_nDdrawtype=2;//表示绘制矩形
CDC*pDC=GetDC(); //使用GetDC()函数申请CDC类的指针
CRect rect(100,0,320,200);
CBrush brush(RGB(180,180,180));//定义画刷
pDC->FillRect(rect,&brush);//填充绘图区域
pDC->Rectangle(160,10,260,110); //画矩形
pDC->TextOut(120,120,"绘制边长为100的正方形");//在矩形下方输出文字
ReleaseDC(pDC);//释放CDC类的指针
}
void CCh6Demo1View::OnUpdateDrawcircle(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nDdrawtype==1);//若为圆形,设置选中标记
}
void CCh6Demo1View::OnUpdateDrawrect(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
pCmdUI->SetCheck(m_nDdrawtype==2);//若为矩形,设置选中标记
}
void CCh6Demo1View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMenu menu; //定义菜单
menu.LoadMenu(IDR_POPUPMENU); //载入浮动菜单资源
CMenu* pM=menu.GetSubMenu(0); //菜单的第一项作为浮动菜单
CPoint pt;
GetCursorPos(&pt); //获得鼠标位置
pM->TrackPopupMenu(TPM_LEFTALIGN,pt.x,pt.y,this); //弹出浮动菜单
CView::OnRButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -