www.pudn.com > as.rar > asView.cpp


// asView.cpp : implementation of the CAsView class 
// 
 
#include "stdafx.h" 
#include "as.h" 
 
#include "asDoc.h" 
#include "asView.h" 
#include "resource.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView 
 
IMPLEMENT_DYNCREATE(CAsView, CView) 
 
BEGIN_MESSAGE_MAP(CAsView, CView) 
	ON_WM_CONTEXTMENU() 
	//{{AFX_MSG_MAP(CAsView) 
	ON_WM_RBUTTONDOWN() 
	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(ID_FILE_PRINT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint) 
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview) 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView construction/destruction 
 
CAsView::CAsView() 
{ 
	// TODO: add construction code here 
    m_strLine=""; 
	m_nIndex=-1; 
} 
 
CAsView::~CAsView() 
{ 
} 
 
BOOL CAsView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView drawing 
 
void CAsView::OnDraw(CDC* pDC) 
{ 
	CAsDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView printing 
 
BOOL CAsView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CAsView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CAsView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView diagnostics 
 
#ifdef _DEBUG 
void CAsView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CAsView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CAsDoc* CAsView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CAsDoc))); 
	return (CAsDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CAsView message handlers 
 
void CAsView::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_AS_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 CAsView::OnRButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CMenu menu; 
	menu.LoadMenu(IDR_MENU1); 
 
	CMenu * pPopup=menu.GetSubMenu(0); 
	ClientToScreen(&point); 
	pPopup->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON,point.x,point.y,this); 
 
	CView::OnRButtonDown(nFlags, point); 
} 
 
void CAsView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CClientDC dc(this); 
	if(nChar==0x0d) 
	{ 
		if(++m_nIndex==0) 
		{ 
			menu.CreatePopupMenu(); 
			GetParent()->GetMenu()->AppendMenu(MF_POPUP,(UINT)menu.m_hMenu,"phoneBook"); 
			GetParent()->DrawMenuBar(); 
		} 
	    //m_nIndex+=1; 
		menu.AppendMenu(MF_STRING,m_nIndex+IDM_PHONE1,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 CAsView::OnPhone1()  
{ 
	// TODO: Add your command handler code here 
	CClientDC dc(this); 
	dc.TextOut(0,0,m_strArray.GetAt(0)); 
} 
 
void CAsView::OnPhone2()  
{ 
	// TODO: Add your command handler code here 
	CClientDC dc(this); 
	dc.TextOut(0,0,m_strArray.GetAt(1)); 
} 
 
void CAsView::OnPhone3()  
{ 
	// TODO: Add your command handler code here 
	CClientDC dc(this); 
	dc.TextOut(0,0,m_strArray.GetAt(2)); 
}