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

📄 transparentwnd.cpp

📁 最新visualC++编程200例书籍源码包括对数据库的操作
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			CPoint ptOffset((m_ptDest.x > rcW.left)?5:-5,(m_ptDest.y > rcW.top)?5:-5);
			
			rcW+=ptOffset;
			MoveWindow(rcW);
			
			if(m_ptDest.x<rcW.left)		//向左运动
			{
				sprintf(szBmp,"WALK%d",m_iAniSeq%12+1);
				m_iLastDirection=1;
			}
			else						//向右运动
			{
				sprintf(szBmp,"WALK%d",m_iAniSeq%12+13);
				m_iLastDirection=2;
			}
			
		}
		else
		{
			int xcounter=5,ycounter=5;	//设置精灵行走步长
			
			m_Rect=GetTopWndTitleRect();
			if(rcW.left < m_Rect.left +30 || m_iLastDirection==2) 
			{
				xcounter=5;
				m_iLastDirection=2;
			}
			if(rcW.left > m_Rect.right -30 || m_iLastDirection==1)
			{
				xcounter=-5;
				m_iLastDirection=1;
			}
			ycounter=0;                       //上、下位置不变
			
			rcW.top =m_Rect.top-rcW.Height();
			rcW.bottom =m_Rect.top;
			
			CPoint ptOffset(xcounter,ycounter);
			rcW+=ptOffset;
			
			MoveWindow(rcW);
			
			if((m_iAniSeq%80)==0)           //局部运动时,往右为奔跑
			{
				KillTimer(GetCurAction());
				SetTimer(TIMER_IDLE,300,NULL);	
			}
			else if((m_iAniSeq%30)==0)
			{
				KillTimer(GetCurAction());
				SetTimer(TIMER_TRANSFORM,300,NULL);	
			}
			
			if(m_iLastDirection==1)			  //向左运动
			{
				sprintf(szBmp,"WALK%d",m_iAniSeq%12+1);
			}
			else							  //向右运动
			{
				sprintf(szBmp,"WALK%d",m_iAniSeq%12+13);
			}
		}
		
		int CurAction;
		if((CurAction=GetCurAction())!=TIMER_WALK)
			KillTimer(CurAction);

		m_bmpDraw.DeleteObject();
		m_bmpDraw.LoadBitmap(szBmp);
		CWindowDC dc(this);
		SetupRegion(&dc);
		Invalidate();
	}
}

//********************************************************************************
//* 名称:DoRun()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:奔跑
//********************************************************************************
void CTransparentWnd::DoRun(void)
{
	if(!m_bRest)				//如果不是静止的话
	{
		char szBmp[20];
		CRect rcW;
		GetWindowRect(rcW);
		
		//决定全屏或局部运动的范围,暂只考虑任务条在下方时情况
		if(m_bFullScreenWalk)
		{
			if((m_ptDest.x> rcW.left && m_ptDest.x < rcW.right)||(m_ptDest.y> rcW.top && m_ptDest.y < rcW.bottom ))
			{
				KillTimer(TIMER_RUN);
				SetTimer(TIMER_SET,10,NULL);
				return;
			}
			CPoint ptOffset((m_ptDest.x > rcW.left)?10:-10,(m_ptDest.y > rcW.top)?5:-5);
			rcW+=ptOffset;
			MoveWindow(rcW);
			
			if(m_ptDest.x<rcW.left)  //向左运动
			{
				sprintf(szBmp,"RUN%d",m_iAniSeq%5+1);
				m_iLastDirection=1;
			}
			else                     //向右运动
			{
				sprintf(szBmp,"RUN%d",m_iAniSeq%5+6);
				m_iLastDirection=2;
			}
		}
		else
		{
			int xcounter=10,ycounter=10;
			
			m_Rect=GetTopWndTitleRect();
			if(rcW.left < m_Rect.left +30 || m_iLastDirection==2) 
			{
				xcounter=10;
				m_iLastDirection=2;
			}
			if(rcW.left > m_Rect.right -30 || m_iLastDirection==1)
			{
				xcounter=-10;
				m_iLastDirection=1;
			}
			ycounter=0;                        //上、下位置不变
			
			rcW.top =m_Rect.top-rcW.Height();
			rcW.bottom =m_Rect.top;
			
			CPoint ptOffset(xcounter,ycounter);
			rcW+=ptOffset;
			
			MoveWindow(rcW);
			
			if(m_iLastDirection==1)				//局部运动时,往左为散步
			{
				KillTimer(GetCurAction());
				SetTimer(TIMER_WALK,150,NULL);	
			}
			else if((m_iAniSeq%30)==0)
			{
				KillTimer(GetCurAction());
				SetTimer(TIMER_IDLE,300,NULL);
			}
			
			if(m_iLastDirection==1)				//向左运动
			{
				sprintf(szBmp,"RUN%d",m_iAniSeq%5+1);
			}
			else							    //向右运动
			{
				sprintf(szBmp,"RUN%d",m_iAniSeq%5+6);
			}
		}
		
		m_bmpDraw.DeleteObject();
		m_bmpDraw.LoadBitmap(szBmp);
		CWindowDC dc(this);
		SetupRegion(&dc);
		Invalidate();
	}
}

//********************************************************************************
//* 名称:DoIdle()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:休息
//********************************************************************************
void CTransparentWnd::DoIdle(void)
{
	if(!m_bRest)						  //如果不是静止的话
	{
		CWnd * pFrame;					  //得到当前窗体指针
		
		//是否局部运动范围,暂只考虑任务条在下方时情况
		if(!m_bFullScreenWalk)
		{
			CRect rcW;
			GetWindowRect(rcW);
			m_Rect=GetTopWndTitleRect();
			
			rcW.top =m_Rect.top-rcW.Height();
			rcW.bottom =m_Rect.top;
			MoveWindow(rcW);
		}
		
		pFrame=AfxGetApp()->GetMainWnd();
		if(m_iAniSeq%12==0 && pFrame->IsWindowVisible())
		{
			
			//显示提示窗信息
			CRect rc;
			GetWindowRect(&rc);
			CPoint pt;
			pt.x=rc.left +rc.Width ()/2;
			pt.y=rc.top;
			if(m_bRing)						       //闹铃时提示窗
			{
				m_Tip.Show(_T("时间到了,该起床了!"),&pt);

				if(!m_bMute)
					SoundPlay();			        //播放声音    
			}
			else if(m_bDownloadFailed)		        //在线提示窗
			{
				if(m_bShowNews)                     //显示新闻标志为真
				{
					CString str;

					if(m_sdFile.ReadString(str) == NULL)
					{
						m_sdFile.SeekToBegin();
						m_sdFile.ReadString(str);
					}
					str.Replace("&&",_T("\n"));     //处理字符串换行标志"&&",多行显示
					m_Tip.SetHideDelay(10000);      //显示10秒
					m_Tip.Show(str,&pt);		    //作者注:同一行中显示的字数不能过大
					
					if(!m_bMute)
						SoundPlay();			    //播放声音   
				}
				else
				{
					m_Tip.SetHideDelay(100);
					m_Tip.Hide();
				}   
			}
//			else									//断线时提示窗
//				m_Tip.Show(_T("欢迎您,来到未来工作室!"),&pt);
			
			m_Tip.Hide();

			m_iSecondNum++;
		}

		if( m_bDownloadFailed && m_bShowNews)        //在线时
		{
			if(m_iSecondNum >= 10 )					 //(>=10)秒时关闭它,不再显示提示窗
			{
				m_Tip.SetHideDelay(100); 
				m_Tip.Hide();
				KillTimer(TIMER_IDLE);
				SetTimer(TIMER_SET,100,NULL);
				m_iSecondNum = 0;
				
				return;
			}
		}
		else
		{
			if(m_iSecondNum >= 1 )					//(>=1)秒时关闭它,不再显示提示窗
			{
				m_Tip.SetHideDelay(100); 
				m_Tip.Hide();
				KillTimer(TIMER_IDLE);
				SetTimer(TIMER_SET,100,NULL);
				m_iSecondNum = 0;
				
				return;
			}
		}
		
		int CurAction;
		if((CurAction=GetCurAction())!=TIMER_IDLE)
			KillTimer(CurAction);

		char szBmp[20];	
		sprintf(szBmp,"IDLE%d",m_iAniSeq%4+1);
		
		m_bmpDraw.DeleteObject();
		m_bmpDraw.LoadBitmap(szBmp);
		CWindowDC dc(this);
		SetupRegion(&dc);
		Invalidate();
	}
}

//********************************************************************************
//* 名称:DoTransform()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:变形行为表现
//********************************************************************************
void CTransparentWnd::DoTransform(void)                
{
	if(!m_bRest)          //如果不是静止的话
	{
		char szBmp[20];	
		sprintf(szBmp,"TRANSFORM%d",m_iAniSeq%13+1);
		
		if(strcmp(szBmp,"TRANSFORM13")==0)
		{
			KillTimer(TIMER_TRANSFORM);
			SetTimer(TIMER_SET,10,NULL);
			return;
		}
		
		//是否局部运动的范围,暂只考虑任务条在下方时情况
		if(!m_bFullScreenWalk)
		{
			CRect rcW;
			GetWindowRect(rcW);
			m_Rect=GetTopWndTitleRect();
			
			rcW.top =m_Rect.top-rcW.Height();
			rcW.bottom =m_Rect.top;
			MoveWindow(rcW);
		}
		
		int CurAction;
		if((CurAction=GetCurAction())!=TIMER_TRANSFORM)
			KillTimer(CurAction);

		m_bmpDraw.DeleteObject();
		m_bmpDraw.LoadBitmap(szBmp);
		CWindowDC dc(this);
		SetupRegion(&dc);
		Invalidate();
	}
}

//********************************************************************************
//* 名称:DoDrag()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:拖动窗体时行为表现
//********************************************************************************
void CTransparentWnd::DoDrag(void)
{

	CRect rcW;
	POINT point;
	GetWindowRect(rcW);

	//实现拖动时窗体跟着移动
    ::GetCursorPos(&point);			
	MoveWindow(point.x-m_ptCurPoint.x ,point.y-m_ptCurPoint.y ,rcW.Width(),rcW.Height() ,true); 

	char szBmp[20];

	sprintf(szBmp,"SLING%d",m_iAniSeq%8+1);

	m_bmpDraw.DeleteObject();
	m_bmpDraw.LoadBitmap(szBmp);
	CWindowDC dc(this);
	SetupRegion(&dc);
	Invalidate();

}

//********************************************************************************
//* 名称:DoFall()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:拖动后的下落表现
//********************************************************************************
void CTransparentWnd::DoFall(void)
{
	CRect rcW,m_Rect;
	GetWindowRect(&rcW);
	
	m_Rect=GetTopWndTitleRect();
	if( rcW.bottom >= m_Rect.top )
	{
		KillTimer(TIMER_FALL);
		SetTimer(TIMER_SET,10,NULL);
		return;
	}

	MoveWindow(rcW.left,rcW.top+10,rcW.Width(),rcW.Height(),true); 
}

//********************************************************************************
//* 名称:OnLButtonDown()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:实现窗体无标题拖动
//********************************************************************************
void CTransparentWnd::OnLButtonDown(UINT nFlags, CPoint point) 
{
	CWnd::OnLButtonDown(nFlags, point);

	KillTimer(GetCurAction());		   //关闭当前行为表现

	SetTimer(TIMER_DRAGDROP,60,NULL);  //打开拖动时计数器

	//鼠标移动到窗体时改变鼠标指针
	::SetCursor(AfxGetApp()->LoadCursor(IDC_DROP));

	m_bDragDrop=true;					//精灵助手拖动标志为真
	SetCapture();						//设置鼠标全屏捕捉
    m_ptCurPoint=point;					//记下按下时的鼠标坐标

//	PostMessage(WM_NCLBUTTONDOWN, HTCAPTION, MAKELPARAM(point.x,point.y));

}

//********************************************************************************
//* 名称:OnLButtonUp()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:实现窗体实时拖动效果
//********************************************************************************
void CTransparentWnd::OnLButtonUp(UINT nFlags, CPoint point) 
{
	
	m_bDragDrop=false;				//精灵助手拖动标志为假
	ReleaseCapture();
	KillTimer(TIMER_DRAGDROP);		//关闭拖动时记数器 

	SetTimer(TIMER_FALL,100,NULL);  //启动下落表现
	
	CWnd::OnLButtonUp(nFlags, point);
}

//********************************************************************************
//* 名称:OnCreate()
//* 作者:徐景周(jingzhou_xu@163.net)
//* 功能:创建窗体
//********************************************************************************
int CTransparentWnd::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CWnd::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	//系统区显示的图标文件
	m_hIcon[0]=AfxGetApp()->LoadIcon(IDI_TRAYICON);
    
	//创建系统区图标
	if (!m_TrayIcon.Create(this, 

⌨️ 快捷键说明

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