www.gusucode.com > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序 > 《C++高级语言程序设计》PPT及全书例子源代码-源码程序/code/C++例题程序/第10章/s10_3/s10_3View.cpp
//Download by http://www.NewXing.com // s10_3View.cpp : implementation of the CS10_3View class // #include "stdafx.h" #include "s10_3.h" #include "s10_3Doc.h" #include "s10_3View.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CS10_3View IMPLEMENT_DYNCREATE(CS10_3View, CView) BEGIN_MESSAGE_MAP(CS10_3View, CView) //{{AFX_MSG_MAP(CS10_3View) ON_WM_LBUTTONDBLCLK() //}}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() ///////////////////////////////////////////////////////////////////////////// // CS10_3View construction/destruction CS10_3View::CS10_3View() { // TODO: add construction code here // 初始化鼠标坐标,-1表示初始时还没双击鼠标,不显示文本 m_xMousePosition = m_yMousePosition = -1; } CS10_3View::~CS10_3View() { } BOOL CS10_3View::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } ///////////////////////////////////////////////////////////////////////////// // CS10_3View drawing void CS10_3View::OnDraw(CDC* pDC) { CS10_3Doc* pDoc = GetDocument(); ASSERT_VALID(pDoc); // TODO: add draw code for native data here if(m_xMousePosition != -1) { LOGFONT sLogFont; // 定义字体结构 sLogFont.lfCharSet = ANSI_CHARSET; sLogFont.lfEscapement = 0; sLogFont.lfHeight = 60; sLogFont.lfItalic = 0; sLogFont.lfOrientation = 0; sLogFont.lfPitchAndFamily = DEFAULT_PITCH; sLogFont.lfQuality = DEFAULT_QUALITY; sLogFont.lfStrikeOut = 0; sLogFont.lfUnderline = 0; sLogFont.lfWeight = FW_NORMAL; sLogFont.lfWidth = 0; strcpy(sLogFont.lfFaceName,"times new roman"); CClientDC oDC(this); // oDC为当前客户区 CFont oFont; // 定义字体 CFont *pOldFont; // 定义旧字体指针 oFont.CreateFontIndirect(&sLogFont); // 创建字体 pOldFont = oDC.SelectObject(&oFont); // 选择字体 oDC.TextOut(m_xMousePosition, m_yMousePosition, "欢迎学习Visual C++ 6.0!"); oDC.SelectObject(pOldFont); // 还原旧字体 } } ///////////////////////////////////////////////////////////////////////////// // CS10_3View printing BOOL CS10_3View::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void CS10_3View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void CS10_3View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } ///////////////////////////////////////////////////////////////////////////// // CS10_3View diagnostics #ifdef _DEBUG void CS10_3View::AssertValid() const { CView::AssertValid(); } void CS10_3View::Dump(CDumpContext& dc) const { CView::Dump(dc); } CS10_3Doc* CS10_3View::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CS10_3Doc))); return (CS10_3Doc*)m_pDocument; } #endif //_DEBUG ///////////////////////////////////////////////////////////////////////////// // CS10_3View message handlers void CS10_3View::OnLButtonDblClk(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default m_xMousePosition = point.x; m_yMousePosition = point.y; Invalidate(); CView::OnLButtonDblClk(nFlags, point); }