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

📄 character_motionview.cpp

📁 设置文字使文字在屏幕是运动,当运动到最右边,则另起一行重新运动
💻 CPP
字号:
// character_motionView.cpp : implementation of the CCharacter_motionView class
//

#include "stdafx.h"
#include "character_motion.h"
#include "dialog11.h"
#include "dialog2.h"
#include "dialog4.h"

#include "character_motionDoc.h"
#include "character_motionView.h"

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

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView

IMPLEMENT_DYNCREATE(CCharacter_motionView, CView)

BEGIN_MESSAGE_MAP(CCharacter_motionView, CView)
	//{{AFX_MSG_MAP(CCharacter_motionView)
	ON_WM_TIMER()
	ON_COMMAND(ID_START, OnStart)
	ON_COMMAND(ID_STOP, OnStop)
	ON_COMMAND(ID_PAUSE, OnPause)
	ON_COMMAND(ID_SPEED, OnSpeed)
	ON_COMMAND(ID_RANGE, OnRange)
	ON_COMMAND(ID_SETFONT, OnSetfont)
	ON_COMMAND(ID_SETSTRING, OnSetstring)
	ON_COMMAND(ID_SET_COLOR, OnSetColor)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView construction/destruction

CCharacter_motionView::CCharacter_motionView()
{
	color=RGB(0,0,0);
	name="";
	s=0;
	x=0;
	y=0;
	xx1=0;
	xx2=0;
	yy1=0;
	yy2=0;
	w=0;
	h=0;
	// TODO: add construction code here

}

CCharacter_motionView::~CCharacter_motionView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView drawing

void CCharacter_motionView::OnDraw(CDC* pDC)
{
	CCharacter_motionDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	CFont font;
		VERIFY(font.CreateFontIndirect(&lf));
		CClientDC dc(this);
		dc.SetTextColor(color);
		CFont* def_font=dc.SelectObject(&font);
		CSize cs=dc.GetTextExtent(name);
		w=cs.cx;
		h=cs.cy;
	dc.TextOut(xx1+x,yy1+y,name);
	dc.SelectObject(def_font);
	font.DeleteObject();

}

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CCharacter_motionView message handlers

void CCharacter_motionView::OnTimer(UINT nIDEvent) 
{
	if(x>xx2)
	{
		x=0;
		y=rand()%(yy2-h);
	}
	
	Invalidate(TRUE);
	x+=5;
	
	CView::OnTimer(nIDEvent);
}

void CCharacter_motionView::OnStart() 
{
	if(name=="")
	{
			AfxMessageBox("文字不能为空,请重试!!!",MB_OK|MB_ICONSTOP);
			OnSetstring();
	}
	else if(xx2==0 || yy2==0)
	{
		AfxMessageBox("范围不合理,请重试!!!",MB_OK|MB_ICONSTOP);
		OnRange();
	}
	else
	m_timer=SetTimer(1,100-s,NULL);
	
}

void CCharacter_motionView::OnStop() 
{
	x=0;
	y=0;
	KillTimer(m_timer);
	Invalidate(TRUE);
	
}

void CCharacter_motionView::OnPause() 
{
	KillTimer(m_timer);
	
}

void CCharacter_motionView::OnSpeed() 
{
	dialog11 dlg11;
	if(dlg11.DoModal()==IDOK)
	{
		s=dlg11.sss;
		OnPause();

	}
}

void CCharacter_motionView::OnRange() 
{
	dialog2 dlg2;
	if(dlg2.DoModal()==IDOK)
	{
		if(dlg2.x1<0  || dlg2.x2<w || (dlg2.x2+w)>750 || 
		   dlg2.y1<0  || dlg2.y2<h || (dlg2.y2+h)>420 ||
		   (dlg2.x2-dlg2.x1)<w || (dlg2.y2-dlg2.y1)<h)
					AfxMessageBox("范围不合理(字体尺寸为零时x方向0--750,y方向0--420),请重试!!!",MB_OK|MB_ICONSTOP);
			
		else
		{
			xx1=dlg2.x1;
		    xx2=dlg2.x2;
		    yy1=dlg2.y1;
		    yy2=dlg2.y2;
		}
	}
}

void CCharacter_motionView::OnSetfont() 
{
	CFontDialog dlg;
	if(dlg.DoModal()==IDOK)
	{
		memcpy(&lf,dlg.m_cf.lpLogFont,sizeof(LOGFONT));
		
		Invalidate(TRUE);
	}
}

void CCharacter_motionView::OnSetstring() 
{
	dialog4 dlg4;
	if(dlg4.DoModal()==IDOK)
	{
		name=dlg4.n;
		Invalidate(TRUE);
	}
	
}

void CCharacter_motionView::OnSetColor() 
{
	CColorDialog cdlg;
	if(cdlg.DoModal()==IDOK)
		color=cdlg.GetColor();
	Invalidate(TRUE);
	/**TRACE("获取颜色的RGB值为 -red=%u,green=%u,blue=%u\n",
		GetRValue(color),GetGValue(color),GetBValue(color));**/

}

⌨️ 快捷键说明

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