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

📄 poetryview.cpp

📁 利用MFC制作的可视界面演示律诗绝句生成过程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PoetryView.cpp : implementation of the CPoetryView class
//

#include "stdafx.h"
#include "Poetry.h"

#include "PoetryDoc.h"
#include "PoetryView.h"

#include <fstream.h>

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

CSize csize;

/////////////////////////////////////////////////////////////////////////////
// CPoetryView

IMPLEMENT_DYNCREATE(CPoetryView, CView)

BEGIN_MESSAGE_MAP(CPoetryView, CView)
	//{{AFX_MSG_MAP(CPoetryView)
	ON_WM_PAINT()
	ON_COMMAND(IDM_ZETOZE, OnZetoze)
	ON_COMMAND(IDM_ZETOPING, OnZetoping)
	ON_COMMAND(IDM_PINGTOZE, OnPingtoze)
	ON_COMMAND(IDM_PINGTOPING, OnPingtoping)
	ON_COMMAND(IDM_TYPEA, OnTypea)
	ON_WM_TIMER()
	ON_WM_CREATE()
	ON_COMMAND(IDM_TYPEB, OnTypeb)
	ON_COMMAND(IDM_TYPEC, OnTypec)
	ON_COMMAND(IDM_TYPED, OnTyped)
	ON_COMMAND(IDM_EXTERN, OnExtern)
	ON_COMMAND(IDM_RECOVER, OnRecover)
	ON_COMMAND(IDM_EXAMPLE, OnExample)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CPoetryView construction/destruction

CPoetryView::CPoetryView()
{
	// TODO: add construction code here
	m_Poetype=0;
	m_Cuttype=0;
	m_Sevenwords=FALSE;
	m_newoper=FALSE;
}

CPoetryView::~CPoetryView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CPoetryView drawing

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

/////////////////////////////////////////////////////////////////////////////
// CPoetryView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CPoetryView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CPoetryView message handlers

void CPoetryView::GetStringFromFile(	LPCTSTR	lpSectionName,
								LPCTSTR	lpKeyName,
								LPTSTR	lpReturnedString,
								LPCTSTR	lpDefault,
								LPCTSTR lpFileName)
{
	char temp[MAX_PATH];
	DWORD nSize = MAX_PATH;
	DWORD nGetSize;
	
	
	nGetSize = GetPrivateProfileString(	lpSectionName,
		lpKeyName,
		lpDefault,
		temp,
		nSize,
		lpFileName );
	strcpy(lpReturnedString, temp);
}


int CPoetryView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CClientDC dc(this);
	CString str;
	char pData[64],pLine[20];
	GetStringFromFile("Type2",itoa(1,pLine,10),pData,"",FILE_POETRYINFO);
	str=pData;
	csize=dc.GetTextExtent(str);
	return 0;
}

void CPoetryView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	if(m_Poetype==1 && !m_Sevenwords)
		dc.TextOut(10,10,"五言仄起仄收式");
	if(m_Poetype==2 && !m_Sevenwords)
		dc.TextOut(10,10,"五言仄起平收式");
	if(m_Poetype==3 && !m_Sevenwords)
		dc.TextOut(10,10,"五言平起仄收式");
	if(m_Poetype==4 && !m_Sevenwords)
		dc.TextOut(10,10,"五言平起平收式");
	if(m_Poetype==1 && m_Sevenwords)
		dc.TextOut(10,10,"七言平起仄收式");
	if(m_Poetype==2 && m_Sevenwords)
		dc.TextOut(10,10,"七言平起平收式");
	if(m_Poetype==3 && m_Sevenwords)
		dc.TextOut(10,10,"七言仄起仄收式");
	if(m_Poetype==4 && m_Sevenwords)
		dc.TextOut(10,10,"七言仄起平收式");

	CFont font;
	font.CreatePointFont(300,"华文行楷");
	CFont *pOldFont=dc.SelectObject(&font);
	
	TEXTMETRIC tm;
	dc.GetTextMetrics(&tm);
	
	
	CString str1,str2;
	char pData[64],pLine[20];
	str1.Format("Type%d",m_Poetype);
	for(int i=0;i<8;i++)
	{		
		GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
		str2=pData;
		dc.TextOut(400,40+i*tm.tmHeight,str2);
	}
	
	if(!m_Sevenwords && m_Cuttype==1 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=0;i<4;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400,40+i*tm.tmHeight,str2);
		}
	}

	if(!m_Sevenwords && m_Cuttype==2 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=4;i<8;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400,40+i*tm.tmHeight,str2);
		}
	}

	if(!m_Sevenwords && m_Cuttype==3 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=2;i<6;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400,40+i*tm.tmHeight,str2);
		}
	}

	if(!m_Sevenwords && m_Cuttype==4 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=0;i<2;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400,40+i*tm.tmHeight,str2);
		}
		for(i=6;i<8;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400,40+i*tm.tmHeight,str2);
		}
	}
	
	
	if(m_Sevenwords)
	{
		dc.SetTextColor(RGB(0,0,255));
		str1.Format("Type%d",m_Poetype);
		for(int i=0;i<8;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYEXTERN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400-sz.cx,40+i*tm.tmHeight,str2);
		}
		
	}


	if(m_Sevenwords && m_Cuttype==1 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=0;i<4;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400-csize.cx+9,40+i*tm.tmHeight,str2);
		}
	}
	
	if(m_Sevenwords && m_Cuttype==2 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=4;i<8;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400-csize.cx+9,40+i*tm.tmHeight,str2);
		}
	}
	
	if(m_Sevenwords && m_Cuttype==3 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=2;i<6;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400-csize.cx+9,40+i*tm.tmHeight,str2);
		}
	}
	
	if(m_Sevenwords && m_Cuttype==4 && !m_newoper)
	{
		dc.SetTextColor(RGB(255,0,0));
		str1.Format("Type%d",m_Poetype);
		for(int i=0;i<2;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);
			dc.TextOut(400-csize.cx+9,40+i*tm.tmHeight,str2);
		}
		for(i=6;i<8;i++)
		{		
			GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
			str2=pData;
			CSize sz=dc.GetTextExtent(str2);

⌨️ 快捷键说明

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