contextmenuview.cpp
来自「《VC++ 编程技巧与示例 .rar》各个示例代码绝对可用」· C++ 代码 · 共 142 行
CPP
142 行
// ContextMenuView.cpp : implementation of the CContextMenuView class
//
#include "stdafx.h"
#include "ContextMenu.h"
#include "ContextMenuDoc.h"
#include "ContextMenuView.h"
#include "resource.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView
IMPLEMENT_DYNCREATE(CContextMenuView, CView)
BEGIN_MESSAGE_MAP(CContextMenuView, CView)
ON_WM_CONTEXTMENU()
//{{AFX_MSG_MAP(CContextMenuView)
ON_COMMAND(ID_VIEW, OnView)
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView construction/destruction
CContextMenuView::CContextMenuView()
{
// TODO: add construction code here
}
CContextMenuView::~CContextMenuView()
{
}
BOOL CContextMenuView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView drawing
void CContextMenuView::OnDraw(CDC* pDC)
{
CContextMenuDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
}
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView printing
BOOL CContextMenuView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CContextMenuView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CContextMenuView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView diagnostics
#ifdef _DEBUG
void CContextMenuView::AssertValid() const
{
CView::AssertValid();
}
void CContextMenuView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CContextMenuDoc* CContextMenuView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CContextMenuDoc)));
return (CContextMenuDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CContextMenuView message handlers
void CContextMenuView::OnContextMenu(CWnd*, CPoint point)
{
// CG: This block was added by the Pop-up Menu component { if (point.x == -1 && point.y == -1){ //keystroke invocation CRect rect; GetClientRect(rect); ClientToScreen(rect); point = rect.TopLeft(); point.Offset(5, 5); } CMenu menu; VERIFY(menu.LoadMenu(CG_IDR_POPUP_CONTEXT_MENU_VIEW)); CMenu* pPopup = menu.GetSubMenu(0); ASSERT(pPopup != NULL); CWnd* pWndPopupOwner = this; while (pWndPopupOwner->GetStyle() & WS_CHILD) pWndPopupOwner = pWndPopupOwner->GetParent(); pPopup->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, point.x, point.y, pWndPopupOwner); }
}
void CContextMenuView::OnView()
{
// TODO: Add your command handler code here
AfxMessageBox("View Reporting!");
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?