ex030101view.cpp
来自「深入浅出Visual C++入门进阶与应用实例 随书光盘 作者 何志丹」· C++ 代码 · 共 144 行
CPP
144 行
// Ex030101View.cpp : implementation of the CEx030101View class
//
#include "stdafx.h"
#include "Ex030101.h"
#include "Ex030101Doc.h"
#include "Ex030101View.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx030101View
IMPLEMENT_DYNCREATE(CEx030101View, CView)
BEGIN_MESSAGE_MAP(CEx030101View, CView)
//{{AFX_MSG_MAP(CEx030101View)
ON_WM_LBUTTONDOWN()
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()
/////////////////////////////////////////////////////////////////////////////
// CEx030101View construction/destruction
CEx030101View::CEx030101View()
{
// TODO: add construction code here
}
CEx030101View::~CEx030101View()
{
}
BOOL CEx030101View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx030101View drawing
void CEx030101View::OnDraw(CDC* pDC)
{
CEx030101Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CEx030101View printing
BOOL CEx030101View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx030101View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx030101View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEx030101View diagnostics
#ifdef _DEBUG
void CEx030101View::AssertValid() const
{
CView::AssertValid();
}
void CEx030101View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx030101Doc* CEx030101View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx030101Doc)));
return (CEx030101Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx030101View message handlers
void CEx030101View::OnLButtonDown(UINT nFlags, CPoint point)
{
CMenu menu ;
menu.LoadMenu(IDR_MAINFRAME);//加截主菜单
CMenu * pMenu = menu.GetSubMenu(1); //取得第二列
if(NULL == pMenu)//出错
{
ASSERT(false);//便于调试
return ;
}
//客户坐标转屏幕坐标
//快捷菜单是以屏幕左上角为坐标原点,而应用程序的鼠标坐标以客户区左上角为坐标原点,故需要进行转换
this->ClientToScreen(&point);
pMenu->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);//弹出菜单
CView::OnLButtonDown(nFlags, point);
}
void CEx030101View::OnRButtonDown(UINT nFlags, CPoint point)
{
CMenu menu ;
menu.CreatePopupMenu();
//增加菜单项
menu.AppendMenu(MF_STRING,ID_EDIT_UNDO,"撤消(&U)\tCtrl+Z");
menu.AppendMenu( MF_SEPARATOR);
menu.AppendMenu(MF_STRING,ID_EDIT_CUT,"剪切(&T)\tCtrl+X");
//..
this->ClientToScreen(&point);
menu.TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this);//弹出菜单
CView::OnRButtonDown(nFlags, point);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?