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

📄 pictalkdlg.cpp

📁 超强的图形界面聊天软件.rar
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	Msgpack.m_Name=m_pUser->m_Name;
	Msgpack.m_bSit=m_pUser->m_bSit;
	Msgpack.m_pic=m_pUser->m_pic;
	Msgpack.m_IP=m_pUser->m_IP;
	Msgpack.m_Name=m_pUser->m_Name;
	Msgpack.m_nAge=m_pUser->m_nAge;
	Msgpack.m_Sex=m_pUser->m_Sex;
	Msgpack.m_ICQ=m_pUser->m_ICQ;
	Msgpack.m_Job=m_pUser->m_Job;
	Msgpack.m_Address=m_pUser->m_Address;
	Msgpack.m_nPort=m_pUser->m_nPort;
	
	SendMsg(Msgpack);
}

POSITION CPictalkDlg::UserInfo(mpack &Msgpack, POSITION pos)
{
	CUserInfo *tempUser;
	UINT uID;
	m_MapUser.GetNextAssoc(pos,uID,tempUser);
	Msgpack.create();
	Msgpack.m_MsgID=MID_ADDUSER;
	Msgpack.m_ID=tempUser->m_ID;
	Msgpack.m_state=tempUser->m_state;
	Msgpack.m_x=tempUser->m_x;
	Msgpack.m_y=tempUser->m_y;
	Msgpack.m_IP=tempUser->m_IP;
	Msgpack.m_Name=tempUser->m_Name;
	Msgpack.m_bSit=tempUser->m_bSit;
	Msgpack.m_pic=tempUser->m_pic;
	Msgpack.m_nAge=tempUser->m_nAge;
	Msgpack.m_Sex=tempUser->m_Sex;
	Msgpack.m_ICQ=tempUser->m_ICQ;
	Msgpack.m_Job=tempUser->m_Job;
	Msgpack.m_Address=tempUser->m_Address;
	Msgpack.m_nPort=tempUser->m_nPort;
	
	return pos;
}

void CPictalkDlg::GetID(mcom &Msgcom)
{
	m_pUser->m_ID=Msgcom.m_ID;
	mpack::m_OldID=m_pUser->m_ID;
	m_MapUser.SetAt(m_pUser->m_ID,m_pUser);
//	m_pUser->ShowUser();
}

void CPictalkDlg::SendOut()
{
	mpack Msgpack;
	Msgpack.create();
	Msgpack.m_MsgID=MID_DELUSER;
	Msgpack.m_ID=m_pUser->m_ID;
	if(m_bConnected)
		m_pNet->SendMsg(Msgpack,NULL);
}

void CPictalkDlg::DelUser(mcom &Msgcom)
{
	POSITION pos,prvepos;
	CUserInfo *tempUser;
	for( pos = m_pUserList.GetHeadPosition(); pos != NULL; )
	{
		prvepos=pos;
		tempUser=(CUserInfo *)m_pUserList.GetNext(pos);
		if(tempUser->m_ID==Msgcom.m_ID)
		{
//			m_pUserList.RemoveAt(prvepos);
			
//			delete tempUser;
			break;
		}
	};
	m_pUserList.RemoveAt(prvepos);
	m_MapUser.RemoveKey(tempUser->m_ID);
	delete tempUser;
}
void CPictalkDlg::SendMsg(mpack &Msgpack)
{
	CEdit * pEdit=(CEdit *)GetDlgItem(IDC_TALK);
		pEdit->SetFocus();
	Msgpack.create();
	m_pNet->SendMsg(Msgpack,NULL);
}

void CPictalkDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent==1)
	{
		if(roomid){
		g_strShowInfo.Format("id=%d&port=%d&name=%s",roomid,m_PortAddress,m_RoomName);
		AfxBeginThread(ShowWinInetThreadProc,THREAD_PRIORITY_NORMAL);
		}
	}
	if(nIDEvent==2){
		mpack Msgpack;
		Msgpack.create();
		Msgpack.m_MsgID=MID_VISIT;
		SendMsg(Msgpack);
		POSITION pos,pos2;
		for( pos = m_pUserList.GetHeadPosition(); pos != NULL; )
		{
			pos2=pos;
			CUserInfo *tempUser=(CUserInfo *)m_pUserList.GetNext(pos);
			if(tempUser->m_ID!=m_pUser->m_ID){
				tempUser->m_Visit++;
				if(tempUser->m_Visit>3){
					m_pUserList.RemoveAt(pos2);
					m_MapUser.RemoveKey(tempUser->m_ID);
					delete tempUser;
				}
			}
		}
	}

	CDialog::OnTimer(nIDEvent);
}

void CPictalkDlg::Move(UINT dir)
{
	if(m_bConnected)
	{	
		m_cs.Lock();
		if(m_pUser->m_MsgCount)
			return;
		m_pUser->m_MsgCount++;
		m_cs.Unlock();
		if(m_pUser->m_bSit)
		{
			m_pUser->m_MsgCount--;
			return;
		}

		mpack Msgpack;
		Msgpack.m_MsgID=MID_PUBLICMSG;
		if(dir!=m_pUser->m_state)
			Msgpack.m_ComID=MID_TURN;
		else
			Msgpack.m_ComID=MID_MOVE;
		Msgpack.m_ID=m_pUser->m_ID;
		Msgpack.m_state=dir;
		Msgpack.m_x=m_pUser->m_x;
		Msgpack.m_y=m_pUser->m_y;
		Msgpack.m_bSit=m_pUser->m_bSit;
			
		SendMsg(Msgpack);
		m_pUser->m_ComArray.Add(Msgpack);
		return;
	}
}

void CPictalkDlg::OnBkColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	if(dlg.DoModal()==IDOK)
		m_pPW->m_BKColor=dlg.GetColor();
}

void CPictalkDlg::OnFontColor() 
{
	// TODO: Add your command handler code here
	CColorDialog dlg;
	if(dlg.DoModal()==IDOK)
		m_pPW->m_FontColor=dlg.GetColor();
}

void CPictalkDlg::OnButtonAngry() 
{
	// TODO: Add your control notification handler code here
	SingleMsg(MID_ANGRY);
}

void CPictalkDlg::OnButtonCry() 
{
	// TODO: Add your control notification handler code here
	SingleMsg(MID_CRY);
}

void CPictalkDlg::OnButtonSit() 
{
	// TODO: Add your control notification handler code here
	if(m_bConnected){
		if(m_pUser->m_bSit){
			SingleMsg(MID_STAND);
			GetDlgItem(IDC_BUTTON_SIT)->SetWindowText("坐下");
		}
		else{
			SingleMsg(MID_SIT);
			GetDlgItem(IDC_BUTTON_SIT)->SetWindowText("站起");
		}
	}
}

void CPictalkDlg::OnButtonSmile() 
{
	// TODO: Add your control notification handler code here
	SingleMsg(MID_SMILE);
}

void CPictalkDlg::SingleMsg(int nCom)
{
	CEdit * pEdit=(CEdit *)GetDlgItem(IDC_TALK);
	pEdit->SetFocus();
	if(m_bConnected){
	
	if(m_pUser->m_MsgCount==1)
		return;
	m_pUser->m_MsgCount++;
	
	mpack Msgpack;
	Msgpack.m_MsgID=MID_PUBLICMSG;
	Msgpack.m_ComID=nCom;
	Msgpack.m_ID=m_pUser->m_ID;
	Msgpack.m_state=m_pUser->m_state;
	Msgpack.m_x=m_pUser->m_x;
	Msgpack.m_y=m_pUser->m_y;
	Msgpack.m_bSit=m_pUser->m_bSit;

		
	SendMsg(Msgpack);
	m_pUser->m_ComArray.Add(Msgpack);
	}
}

void CPictalkDlg::OnButtonHello() 
{
	// TODO: Add your control notification handler code here
	SingleMsg(MID_HELLO);
}

void CPictalkDlg::StopLink()
{
	delete m_pNet;	
	m_bConnected=FALSE;
	
	POSITION pos,prvepos;
	for( pos = m_pUserList.GetHeadPosition(); pos != NULL; )
	{
		prvepos=pos;
		CUserInfo *tempUser=(CUserInfo *)m_pUserList.GetNext(pos);
		m_pUserList.RemoveAt(prvepos);
		delete tempUser;
	}
//	m_ShowName.ResetContent();
}
void CPictalkDlg::OnAcceptMessage(UINT nID, LPARAM param)
{
/*	m_cs.Lock();
	int i,j;
	j=MsgArray.GetSize();
	for(i=0;i<j;i++)
	{
		CheckMsg(MsgArray[0]);
		MsgArray.RemoveAt(0);
	}
	m_cs.Unlock();*/
}

void CPictalkDlg::OnButtonSen() 
{
	// TODO: Add your control notification handler code here
	if(m_pShowSen==NULL){
		m_pShowSen=new CShowSen(this);
		m_pShowSen->Create(IDD_DIALOG_SENTEN,this);
		int i;
		for(i=0;i<m_SenList.GetSize();i++)
			m_pShowSen->m_ListSen.InsertString(-1,m_SenList[i]);
		m_pShowSen->ShowWindow(SW_SHOW);
	}
	else{
		delete m_pShowSen;
		m_pShowSen=NULL;
	}
/*	CEdit * pEdit=(CEdit *)GetDlgItem(IDC_TALK);
		if(pEdit)
			pEdit->SetFocus();*/
}
LRESULT CPictalkDlg::OnDlgSenClose(WPARAM wParam,LPARAM param)
{
	m_pShowSen->UpdateData();
	if(m_pShowSen->m_Sen!=""){
		m_Sendinfo=m_pShowSen->m_Sen;
		UpdateData(FALSE);
		OnInfoSend();
	}
	else{
		m_pShowSen->DestroyWindow();
		m_pShowSen=NULL;
	}
	return 0L;
}

void CPictalkDlg::AddSenten(CString &str)
{
	m_SenList.Add(str);
	if(m_pShowSen!=NULL){
		m_pShowSen->m_ListSen.InsertString(-1,str);
		m_pShowSen->UpdateData(FALSE);
		m_pShowSen->m_ListSen.SetCurSel(m_pShowSen->m_ListSen.GetCount()-1);
		m_pShowSen->AddSen();
	}
	if(m_SenList.GetSize()>50){
		m_SenList.RemoveAt(0);
		if(m_pShowSen!=NULL){
			m_pShowSen->m_ListSen.DeleteString(0);
			m_pShowSen->UpdateData(FALSE);
		}
	}
}

void CPictalkDlg::OnChangeTalk() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	UpdateData();
	if(m_Sendinfo.GetLength()>48){
		if(m_pShowSen==NULL){
			m_pShowSen=new CShowSen(this);
			m_pShowSen->Create(IDD_DIALOG_SENTEN,this);
			int i;
			for(i=0;i<m_SenList.GetSize();i++)
				m_pShowSen->m_ListSen.InsertString(-1,m_SenList[i]);
			m_pShowSen->ShowWindow(SW_SHOW);
		}
		m_pShowSen->SetFocus();
		m_pShowSen->UpdateData();
		m_pShowSen->m_SenCtrl.SetSel(0,-1);
		m_pShowSen->m_SenCtrl.ReplaceSel(m_Sendinfo);
	}
}

void CPictalkDlg::OnButtonShowinfo() 
{
	// TODO: Add your control notification handler code here
	if(m_pShowInfo==NULL){
		m_pShowInfo=new CShowInfo(this);
		m_pShowInfo->Create(IDD_USERINFO,this);
		m_pShowInfo->ShowWindow(SW_SHOW);
	}
	else{
		m_pShowInfo->DestroyWindow();
		delete m_pShowInfo;
		m_pShowInfo=NULL;
	}
	SetFocus();
}
LRESULT CPictalkDlg::OnDlgInfoClose(WPARAM wParam,LPARAM param)
{
	m_pShowInfo->DestroyWindow();
	delete m_pShowInfo;
	m_pShowInfo=NULL;
	return 0L;
}

void CPictalkDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	CRect ret;
	POSITION pos;
	if(m_pShowInfo){
		for( pos = m_pUserList.GetHeadPosition(); pos != NULL; )
		{
			CUserInfo *tempUser=(CUserInfo *)m_pUserList.GetNext(pos);
			ret=tempUser->m_Place;
			ret.left+=12;
			ret.right+=12;
		
			if(ret.PtInRect(point))
			{
				m_pShowInfo->m_Name="昵称:"+tempUser->m_Name;
				m_pShowInfo->m_IP=tempUser->m_IP;
				m_pShowInfo->m_nAge=tempUser->m_nAge;
				m_pShowInfo->m_Sex=tempUser->m_Sex;
				m_pShowInfo->m_IcqNum=tempUser->m_ICQ;
				m_pShowInfo->m_Job=tempUser->m_Job;
				m_pShowInfo->m_Address=tempUser->m_Address;
				m_pShowInfo->FindIP(tempUser->m_IP);
				m_pShowInfo->UpdateData(FALSE);
		
			}
		}
	}
	CDialog::OnMouseMove(nFlags, point);
}

void CPictalkDlg::Connected()
{
	OnButtonShowinfo();
	SendUser();
}
void CPictalkDlg::OnConnectOver(UINT nID, LPARAM param)
{
	m_pNet->ConnectOver();
}

void CPictalkDlg::OnDestroy() 
{
	CDialog::OnDestroy();
	
	// TODO: Add your message handler code here
	SendOut();
	POSITION pos,pos2;
	for( pos = m_pUserList.GetHeadPosition(); pos != NULL; )
	{
		pos2=pos;
		CUserInfo *tempUser=(CUserInfo *)m_pUserList.GetNext(pos);
		delete	tempUser;
		m_pUserList.RemoveAt(pos2);
	}
}

BOOL CPictalkDlg::IsUser(UINT uID)
{
	CUserInfo * tempUser;
	return m_MapUser.Lookup(uID,tempUser);
}

⌨️ 快捷键说明

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