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

📄 picwnd.cpp

📁 超强的图形界面聊天软件.rar
💻 CPP
字号:
// PicWnd.cpp : implementation file
//

#include "stdafx.h"
#include "pictalk.h"
#include "PicWnd.h"
#include "UserInfo.h"

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

CPicWnd::CPicWnd()
{
	
}

CPicWnd::~CPicWnd()
{
}


/////////////////////////////////////////////////////////////////////////////
// CPicWnd message handlers


void CPicWnd::Create(CWnd * pCwnd,CPtrList * pUserList)
{
	m_pUserList=pUserList;;
	m_pParentWnd=pCwnd;
	m_BKColor=RGB(0,255,255);
	m_FontColor=RGB(255,0,0);
	CClientDC dc(m_pParentWnd);
	CDC bg,show;
	m_Pic.Create(638,367,16,NULL);
	show.CreateCompatibleDC(&dc);
	bg.CreateCompatibleDC(&show);
	
	CString filename="body\\body.txt";
	CStdioFile file;
	if(file.Open(filename,CFile::modeRead)==0){
		AfxMessageBox("读取文件失败",MB_OK);
	}
	CString str;
	CStringArray filearray;
	filearray.RemoveAll();
	while(1){
		file.ReadString(str);
		if(str=="")
			break;
		filearray.Add(str);
	}
	file.Close();
	m_bm.Create(54*32+5,78*filearray.GetSize(),16,NULL);
	
	MaxBody=filearray.GetSize()-1;
	int i;
	for(i=0;i<filearray.GetSize();i++){
		CBmpProc	ccc;
		BOOL hh=ccc.LoadFromFile(filearray[i].GetBuffer(20));
		CRect *pDesRect=new CRect(0,i*78,54*32+5,i*78+78);
		CRect *pSouRect=new CRect(0,0,54*32+5,78);
		m_bm.CopyFromObject(ccc,pDesRect,pSouRect);
	}

//	m_bm.LoadFromFile("girl2.bmp");
	m_bg.LoadFromFile("room1.bmp");
	bg.SelectObject(&m_bm);
	m_COL=bg.GetPixel(0,0);
	bg.SelectObject(&m_bg);
	CBitmap *pod=show.SelectObject(&m_Pic);
	show.BitBlt(0,0,638,436,&bg,0,0,SRCCOPY);
	show.SelectObject(&pod);
}

void CPicWnd::paint()
{
	CClientDC dc(m_pParentWnd);
	CDC memDC;
	CRect rectUpdate;
	dc.GetClipBox(&rectUpdate);
	memDC.CreateCompatibleDC(&dc);
	CBitmap *pod=memDC.SelectObject(&m_Pic);
	dc.BitBlt(rectUpdate.left+12,rectUpdate.top,
		rectUpdate.Width(),rectUpdate.Height(),
		&memDC,
		rectUpdate.left,rectUpdate.top,
		SRCCOPY);
	memDC.SelectObject(pod);
//	draw(1,1,&CRect(10,10,56,88));
}

void CPicWnd::draw(CRect *pRect,CRect *pDelRect)
{

	CClientDC dc(m_pParentWnd);
	CDC memDC;
	CRect tempRect;
	tempRect.UnionRect(pRect,pDelRect);
	if(pDelRect)
		m_Pic.CopyFromObject(m_bg,pDelRect,pDelRect);
	memDC.CreateCompatibleDC(&dc);
	CBitmap * pod=memDC.SelectObject(&m_Pic);
	
	if(!m_pUserList->IsEmpty())
	{
		SetOrder(&tempRect);
		redraw(&memDC);
		DrawSen(&memDC,&tempRect);
	}
	dc.BitBlt(tempRect.left+12,tempRect.top,
		tempRect.Width(),tempRect.Height(),
		&memDC,
		tempRect.left,tempRect.top,
		SRCCOPY);
}

void CPicWnd::draw(int x, int y, int Delx, int Dely)
{
	CRect tempRect;
	if(Delx==-1 && Dely==-1)
		tempRect=NULL;
	else
		tempRect=CRect(Delx,Dely,Delx+54,Dely+78);
	draw(&CRect(x,y,x+54,y+78),&tempRect);
}

void CPicWnd::ShowPic(CDC * pDC,UINT PicID, int PicNum,CRect * pRect, BOOL bTurn)
{
	CRect picRect;
	CBmpProc tempbm;
	tempbm.Create(CSize(54,78),16);
	if(bTurn)
		picRect=CRect(PicNum*54+54,PicID*78,PicNum*54,PicID*78+78);
	else
		picRect=CRect(PicNum*54,PicID*78,PicNum*54+54,PicID*78+78);
	tempbm.CopyFromObject(m_bm,&CRect(0,0,54,78),&picRect);
	tempbm.DrawTransparentInRect(*pDC,m_COL,pRect);
}

void CPicWnd::redraw(CDC * pDC)
{
	POSITION pos;
	for( pos = m_ShowUser.GetHeadPosition(); pos != NULL; )
	{
		CUserInfo *tempUser=(CUserInfo *)m_ShowUser.GetNext(pos);
		ShowPic(pDC,
				tempUser->m_pic,
				tempUser->m_PicNum,
				&tempUser->m_Place,
				tempUser->m_bTurn);
	}
}

void CPicWnd::SetOrder(CRect * pRect)
{
	POSITION pos;
	CRect tempRect;
	CUserInfo *tempUser2;
	m_ShowUser.RemoveAll();
	int top;
	for( pos = m_pUserList->GetHeadPosition(); pos != NULL; )
	{
		CUserInfo *tempUser=(CUserInfo *)m_pUserList->GetNext(pos);
		tempUser->m_bSelect=FALSE;
	}
	while(1)
	{
		tempUser2=NULL;
		top=pRect->bottom;
		for( pos = m_pUserList->GetHeadPosition(); pos != NULL; )
		{
			CUserInfo *tempUser=(CUserInfo *)m_pUserList->GetNext(pos);
			if(tempRect.IntersectRect(pRect,tempUser->m_Place)&&!tempUser->m_bSelect)
				if(tempUser->m_Place.top<top)
				{
					top=tempUser->m_Place.top;
					tempUser2=tempUser;
				}
		}
		if(tempUser2)
		{
			tempUser2->m_bSelect=TRUE;
			m_ShowUser.AddTail(tempUser2);
		}
		else
			break;
	}
}

POSITION CPicWnd::AddSentence(CUserInfo * pUser)
{
	CClientDC dc(m_pParentWnd);
	CDC memDC,PicDC;
	memDC.CreateCompatibleDC(&dc);
	PicDC.CreateCompatibleDC(&dc);
	CString m_sen=pUser->m_sen;
	CSize sensize=memDC.GetTextExtent(m_sen);
	CRect m_TextRect(0,0,100,100);
	int m_Heigh=sensize.cy;
	int m_Width=sensize.cx;
	int i=0,j=1,w,ln=0;
	while(1)
	{
		w=memDC.GetTextExtent(m_sen.Mid(i,j+1)).cx;
		if(w>m_TextRect.Width())
		{
			if(m_sen[i+j]>0)
				m_sen.Insert((i++)+j,'\n');
			i=i+j;
			j=0;
			m_Width=m_TextRect.Width();
			m_Heigh+=sensize.cy;
			ln++;
		}
		j++;
		if(i+j>m_sen.GetLength())
			break;
		if(ln>=3){
			CString temp;
			temp=m_sen.Left(i+j-1)+".....";
			m_sen=temp;
			break;
		}
	}
	CRect rect(0,0,m_Width+8,m_Heigh+8+10);
	CBrush brush(m_FontColor);
	
	CBmpProc *pNewBmp=&pUser->m_SenPic;
	pNewBmp->Create(rect.Size(),16,NULL);
	CBitmap *pod=memDC.SelectObject(pNewBmp);
	memDC.FillRect(rect,&CBrush(m_COL));
	
	CRgn wndRgn,rgnTemp,wndRgn2,rgnTemp2;
	wndRgn.CreateRoundRectRgn(0, 0, m_Width+8, m_Heigh+8,4,4);
	POINT poi[3];
	poi[0].x=rect.Width()/2;poi[0].y=m_Heigh+8+10;
	poi[1].x=rect.Width()/2+5;poi[1].y=m_Heigh;
	poi[2].x=rect.Width()/2-5;poi[2].y=m_Heigh;
	rgnTemp.CreatePolygonRgn(poi,3,ALTERNATE);
	wndRgn.CombineRgn(&wndRgn, &rgnTemp, RGN_OR);
	memDC.FillRgn(&wndRgn,&brush);
	
	wndRgn2.CreateRoundRectRgn(1, 1, m_Width+7, m_Heigh+7,3,3);
	poi[0].x=rect.Width()/2;poi[0].y=m_Heigh+8+9;
	poi[1].x=rect.Width()/2+4;poi[1].y=m_Heigh-1;
	poi[2].x=rect.Width()/2-4;poi[2].y=m_Heigh-1;
	rgnTemp2.CreatePolygonRgn(poi,3,ALTERNATE);
	wndRgn2.CombineRgn(&wndRgn2, &rgnTemp2, RGN_OR);
	memDC.FillRgn(&wndRgn2,&CBrush(m_BKColor));

	memDC.SetBkColor(m_BKColor);
	memDC.SetTextColor(m_FontColor);
	memDC.DrawText(m_sen,CRect(4,4,m_Width+4,m_Heigh+4), DT_WORDBREAK  );
	CPoint tempPoint(pUser->m_Place.left+(pUser->m_Place.Width()-rect.Width())/2,
		pUser->m_Place.top-rect.Height());
	pUser->m_SenPlace=CRect(tempPoint,
		rect.Size());
	PicDC.SelectObject(&m_Pic);

	memDC.SelectObject(pod);
	pNewBmp->DrawTransparentInRect(PicDC,
		m_COL,
		&(pUser->m_SenPlace),
		&rect);
	POSITION pos=m_SenList.AddTail(pUser);
	dc.BitBlt(pUser->m_SenPlace.left+12,
		pUser->m_SenPlace.top,
		pUser->m_SenPlace.Width(),
		pUser->m_SenPlace.Height(),
		&PicDC,
		pUser->m_SenPlace.left,
		pUser->m_SenPlace.top,
		SRCCOPY);
	return pos;
}

void CPicWnd::DrawSen(CDC * pDC,CRect * pRect)
{
	POSITION pos;
	CRect tempRect;
	for( pos = m_SenList.GetHeadPosition(); pos != NULL; )
	{
		CUserInfo *tempUser=(CUserInfo *)m_SenList.GetNext(pos);
		if(tempRect.IntersectRect(pRect,tempUser->m_SenPlace))
			tempUser->m_SenPic.DrawTransparentInRect(*pDC,
				m_COL,
				&(tempUser->m_SenPlace),
				&CRect(0,0,tempUser->m_SenPlace.Width(),tempUser->m_SenPlace.Height()));
	}
}

HRGN CPicWnd::GetRgn(CUserInfo *pUserInfo)
{
	CRect picRect;
	CBmpProc tempbm;
	tempbm.Create(CSize(54,78),16);
	if(pUserInfo->m_bTurn)
		picRect=CRect(pUserInfo->m_PicNum*54+54,
			pUserInfo->m_pic*78,
			pUserInfo->m_PicNum*54,
			pUserInfo->m_pic*78+78);
	else
		picRect=CRect(pUserInfo->m_PicNum*54,
			pUserInfo->m_pic*78,
			pUserInfo->m_PicNum*54+54,
			pUserInfo->m_pic*78+78);
	tempbm.CopyFromObject(m_bm,&CRect(0,0,54,78),&picRect);
	return (tempbm.ExportRegion(m_COL));
}

⌨️ 快捷键说明

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