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

📄 poetryview.cpp

📁 利用MFC制作的可视界面演示律诗绝句生成过程
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			dc.TextOut(400-csize.cx+9,40+i*tm.tmHeight,str2);
		}
	}
		
	// Do not call CView::OnPaint() for painting messages
}




void CPoetryView::OnZetoze() 
{
	// TODO: Add your command handler code here
	m_Poetype=1;
    Invalidate();
}


void CPoetryView::OnZetoping() 
{
	// TODO: Add your command handler code here
	m_Poetype=2;
    Invalidate();
}



void CPoetryView::OnPingtoze() 
{
	// TODO: Add your command handler code here
	m_Poetype=3;
    Invalidate();
}

void CPoetryView::OnPingtoping() 
{
	// TODO: Add your command handler code here
	m_Poetype=4;
    Invalidate();
}

void CPoetryView::OnTypea() 
{
	// TODO: Add your command handler code here
	m_newoper=TRUE;
	Invalidate();
	m_Cuttype=1;
	m_Finish=FALSE;
	m_nWidth=0;
	SetTimer(1,100,NULL);
}


void CPoetryView::OnTypeb() 
{
	// TODO: Add your command handler code here
	m_newoper=TRUE;
	Invalidate();
	m_Cuttype=2;
	m_Finish=FALSE;
	m_nWidth=0;
	SetTimer(2,100,NULL);
	
}

void CPoetryView::OnTypec() 
{
	// TODO: Add your command handler code here
	m_newoper=TRUE;
	Invalidate();
	m_Cuttype=3;
	m_Finish=FALSE;
	m_nWidth=0;
	SetTimer(3,100,NULL);
}

void CPoetryView::OnTyped() 
{
	// TODO: Add your command handler code here
	m_newoper=TRUE;
	Invalidate();
	m_Cuttype=4;
	m_Finish=FALSE;
	m_nWidth=0;
	SetTimer(4,100,NULL);
}


void CPoetryView::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default

		m_nWidth+=5;
		int i,j;
		char pData[68],pLine[20];
		CClientDC dc(this);
		CFont font;
		font.CreatePointFont(300,"华文行楷");
		CFont *pOldFont=dc.SelectObject(&font);
		TEXTMETRIC tm;
		dc.GetTextMetrics(&tm);
		CRect rect;
		CString str1,str2;
		dc.SetTextColor(RGB(255,0,0));
		switch(nIDEvent)
		{
		case 1:
			for(i=0;i<4;i++)
			{
				rect.top=40+i*tm.tmHeight;
				rect.right=400+m_nWidth;
				rect.bottom=rect.top+tm.tmHeight;
				if(m_Cuttype==1 && !m_Finish && m_Sevenwords==FALSE)
				{						
					rect.left=400;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYINFO);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
				if(m_Cuttype==1 && !m_Finish && m_Sevenwords==TRUE)
				{	
					rect.left=400-csize.cx+9;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i,pLine,10),pData,"",FILE_POETRYSEVEN);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
			}
			break;
		case 2:
			for(i=0;i<4;i++)
			{
				rect.top=40+4*tm.tmHeight+i*tm.tmHeight;//3
				rect.right=400+m_nWidth;
				rect.bottom=rect.top+tm.tmHeight;			
				if(m_Cuttype==2 && !m_Finish && m_Sevenwords==FALSE)
				{
					rect.left=400;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i+4,pLine,10),pData,"",FILE_POETRYINFO);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
				if(m_Cuttype==2 && !m_Finish && m_Sevenwords==TRUE)
				{
					rect.left=400-csize.cx+9;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i+4,pLine,10),pData,"",FILE_POETRYSEVEN);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
			}
			break;
		case 3:
			for(i=0;i<4;i++)
			{
				rect.top=40+2*tm.tmHeight+i*tm.tmHeight;//3
				rect.right=400+m_nWidth;
				rect.bottom=rect.top+tm.tmHeight;		
				if(m_Cuttype==3 && !m_Finish && m_Sevenwords==FALSE)
				{
					rect.left=400;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i+2,pLine,10),pData,"",FILE_POETRYINFO);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
				if(m_Cuttype==3 && !m_Finish && m_Sevenwords==TRUE)
				{
					rect.left=400-csize.cx+9;
					str1.Format("Type%d",m_Poetype);
					GetStringFromFile(str1,itoa(i+2,pLine,10),pData,"",FILE_POETRYSEVEN);
					str2=pData;	
					dc.DrawText(str2,rect,DT_LEFT);	
					CSize sz=dc.GetTextExtent(str2);
					if(m_nWidth>sz.cx)
					{
						m_Finish=TRUE;
						m_newoper=FALSE;
					}
				}
			}
			break;
		case 4:		
			for(i=0;i<2;i++)
				for(j=0;j<2;j++)
				{
					rect.top=40+(j+5*i)*tm.tmHeight+i*tm.tmHeight;//3
					rect.right=400+m_nWidth;
					rect.bottom=rect.top+tm.tmHeight;		
					if(m_Cuttype==4 && !m_Finish && m_Sevenwords==FALSE)
					{
						rect.left=400;	
						str1.Format("Type%d",m_Poetype);
						GetStringFromFile(str1,itoa(j+6*i,pLine,10),pData,"",FILE_POETRYINFO);
						str2=pData;	
						dc.DrawText(str2,rect,DT_LEFT);	
						CSize sz=dc.GetTextExtent(str2);
						if(m_nWidth>sz.cx)
						{
							m_Finish=TRUE;
							m_newoper=FALSE;
						}
					}
					if(m_Cuttype==4 && !m_Finish && m_Sevenwords==TRUE)
					{
						rect.left=400-csize.cx+9;	
						str1.Format("Type%d",m_Poetype);
						GetStringFromFile(str1,itoa(j+6*i,pLine,10),pData,"",FILE_POETRYSEVEN);
						str2=pData;	
						dc.DrawText(str2,rect,DT_LEFT);	
						CSize sz=dc.GetTextExtent(str2);
						if(m_nWidth>sz.cx)
						{
							m_Finish=TRUE;
							m_newoper=FALSE;
						}
					}
				}
			break;	
		}
	CView::OnTimer(nIDEvent);
}




void CPoetryView::OnExtern() 
{
	// TODO: Add your command handler code here
	m_Sevenwords=TRUE;
	Invalidate();
}

void CPoetryView::OnRecover() 
{
	// TODO: Add your command handler code here
	m_Sevenwords=FALSE;
	m_newoper=TRUE;
	Invalidate();
}

void CPoetryView::OnExample() 
{
	// TODO: Add your command handler code here
	FILE *pFile;
	char ch[1000];
	memset(ch,0,1000);
	if(m_Poetype==1 && !m_Sevenwords)
	{
		pFile=fopen("5-1.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==2 && !m_Sevenwords)
	{
		pFile=fopen("5-2.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==3 && !m_Sevenwords)
	{
		pFile=fopen("5-3.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==4 && !m_Sevenwords)
	{
		pFile=fopen("5-4.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==1 && m_Sevenwords)
	{
		pFile=fopen("7-1.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==2 && m_Sevenwords)
	{
		pFile=fopen("7-2.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==3 && m_Sevenwords)
	{
		pFile=fopen("7-3.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
	if(m_Poetype==4 && m_Sevenwords)
	{
		pFile=fopen("7-4.txt","r");
		fread(ch,1,1000,pFile);
		MessageBox(ch);
	}
}

⌨️ 快捷键说明

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