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

📄 menu5view.cpp

📁 基于菜单的编程
💻 CPP
字号:
// Menu5View.cpp : implementation of the CMenu5View class
//

#include "stdafx.h"
#include "Menu5.h"

#include "Menu5Doc.h"
#include "Menu5View.h"

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

/////////////////////////////////////////////////////////////////////////////
// CMenu5View

IMPLEMENT_DYNCREATE(CMenu5View, CView)

BEGIN_MESSAGE_MAP(CMenu5View, CView)
	//{{AFX_MSG_MAP(CMenu5View)
	ON_WM_CHAR()
	
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(IDM_PHONE1, OnPhone1)
	ON_COMMAND(IDM_PHONE2, OnPhone2)
	ON_COMMAND(IDM_PHONE3, OnPhone3)
	ON_COMMAND(IDM_PHONE4, OnPhone4)
	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()

/////////////////////////////////////////////////////////////////////////////
// CMenu5View construction/destruction

CMenu5View::CMenu5View()
{
	// TODO: add construction code here
	m_index=-1;
	m_strLine="";
}

CMenu5View::~CMenu5View()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CMenu5View drawing

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

/////////////////////////////////////////////////////////////////////////////
// CMenu5View printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMenu5View diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CMenu5View message handlers

void CMenu5View::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	CClientDC dc(this);
	if(0x0d==nChar)
	{
		if(0==++m_index)
		{
			m_menu.CreatePopupMenu();
			GetParent()->GetMenu()->AppendMenu(MF_POPUP,
				(UINT)m_menu.m_hMenu,"PHONEBOOKS");//添加谈出菜单
			GetParent()->DrawMenuBar();//重绘菜单栏
		}
		m_menu.AppendMenu(MF_STRING,IDM_PHONE1+m_index,
			m_strLine.Left(m_strLine.Find(' ')));//添加谈出菜单项
		m_strArray.Add(m_strLine); //保存字符串组
		m_strLine.Empty();
		Invalidate();//防止重影,使窗口无效。重绘窗口
	}
	else
		{
			m_strLine+=nChar;
			dc.TextOut(0,0,m_strLine);
		}
	
	CView::OnChar(nChar, nRepCnt, nFlags);
}

void CMenu5View::OnPhone1() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	dc.TextOut(0,0,m_strArray.GetAt(0)); //取出 字符串组

}

void CMenu5View::OnPhone2() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	dc.TextOut(0,0,m_strArray.GetAt(1));
}

void CMenu5View::OnPhone3() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	dc.TextOut(0,0,m_strArray.GetAt(2));
}

void CMenu5View::OnPhone4() 
{
	// TODO: Add your command handler code here
	CClientDC dc(this);
	dc.TextOut(0,0,m_strArray.GetAt(3));
}

⌨️ 快捷键说明

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