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

📄 netqqdlg.cpp

📁 类似于QQ的聊天工具,分为客户端和服务器端,有共享空间,能发布公告,可传输文件
💻 CPP
📖 第 1 页 / 共 2 页
字号:
				HANDLE handle = CreateThread(NULL, 0, RecvProc, this, 0, NULL);
				CloseHandle(0);
				break;
			}
		default: break;
	}
}

/*---------------------------------------------------------------------------
 客户信息接收线程    [Modify] dong 12-17
 --------------------------------------------------------------------------*/
DWORD WINAPI CNetQQDlg::RecvProc(LPVOID lpParam)
{
	CNetQQDlg* pLoad = (CNetQQDlg*)lpParam;			/*[Add] dong 12-17*/
	CString strBuff;
	pLoad->GetCClntSock().OnRecieve(strBuff);		/*[Add] dong 12-17*/

	CMsgBag mbTool;
	//提取命令号
	long lOrderType = mbTool.GetOrderCode(strBuff);

	//提取消息状态
	long ret = mbTool.GetRetStatus(strBuff);

	switch(lOrderType)
	{
		//登陆返回
		case 0002:
		{
			CStatic* pTmp = (CStatic*)pLoad->GetDlgItem(IDC_STC_LOADMSG);
			switch(ret)
			{
				case 0:
				{
					pTmp->SetWindowText("密码错误!");
					pLoad->GetCClntSock().CloseClient();
					pLoad->m_FT.CloseFileSocket();
					break;
				}

				case 1:
				{
					pLoad->PostMessage(WM_LOADINMAINDLG, 0, 0);		/*dong 12-17*/
					break;		
				}

				case 2:
				{
					pTmp->SetWindowText("未注册的帐号!");
					pLoad->GetCClntSock().CloseClient();
					pLoad->m_FT.CloseFileSocket();
					break;		
				}
				case 3:
				{
					pTmp->SetWindowText("数据库出错!");
					pLoad->GetCClntSock().CloseClient();
					pLoad->m_FT.CloseFileSocket();
					break;
				}
				case 4:
				{
					pTmp->SetWindowText("此帐号已登陆!");
					pLoad->GetCClntSock().CloseClient();
					pLoad->m_FT.CloseFileSocket();
					break;
				}
			}
			break;
		}

		//接收用户列表
		case 0003:	
		{
			CString strParam[5];
			tagClientInfo* pClient = new tagClientInfo;
			//tagClientInfo* pTemp;

			//解包
			mbTool.SplitDate(strBuff, strParam);

			pClient->m_strUsrId    = strParam[0];
			pClient->m_strIp       = strParam[1];
			pClient->m_strUsrName  = strParam[2];
			pClient->m_strFace     = strParam[3];
			pClient->m_strFilePort = strParam[4];

			WaitForSingleObject(pLoad->GetMutex(), INFINITE);
			pLoad->m_pClntList.AddHead(pClient);
			ReleaseMutex(pLoad->GetMutex());

			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)pClient, 0003);
			}
			break;
		}
		
		//好友资料查询
		case 9004:
		{
			char* strBuf = new char[strBuff.GetLength() + 1];
			strcpy(strBuf, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strBuf, 9004);
			}
			break;
		}

		//好友聊天消息
		case 9005:
		{
			char* strChat = new char[strBuff.GetLength() + 1];
			strcpy(strChat, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strChat, 9005);
			}
			break;
		}
		
		//系统公告
		case 9007:
		{
			char* strCall = new char[strBuff.GetLength() + 1];
			strcpy(strCall, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strCall, 9007);
			}
			break;
		}
		
		//共享文件信息
		case 9009:
		{
			char* strFileIf = new char[strBuff.GetLength() + 1];
			strcpy(strFileIf, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strFileIf, 9009);
			}
			break;
		}
		
		//好友下线
		case 9010:
		{
			CString strParam;

			//解包
			mbTool.SplitDate(CString(strBuff), &strParam);

			tagClientInfo* pTmp;
			POSITION pos1, pos2;

			WaitForSingleObject(pLoad->GetMutex(), INFINITE);	/*dong 12-17*/
			pos1 = pLoad->m_pClntList.GetHeadPosition();
			for(; ( pos2 = pos1 ) != NULL;)
			{
				pTmp = pLoad->m_pClntList.GetNext(pos1);
				if(pTmp->m_strUsrId == strParam)
				{
					pTmp = pLoad->m_pClntList.GetAt(pos2);
					pLoad->m_pClntList.RemoveAt(pos2);
					delete pTmp;
				}
			}
			ReleaseMutex(pLoad->GetMutex());				/*dong 12-17*/

			char* strLeaveUserId = new char[10];
			strcpy(strLeaveUserId, strParam.GetBuffer(0));

			::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strLeaveUserId, 9010);
			break;
		}

		//个人信息返回
		case 9011:
		{
			char* strMe = new char[strBuff.GetLength() + 1];
			strcpy(strMe, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strMe, 9011);
			}
			break;
		}

		//个人信息修改返回
		case 9012:
		{
			char* strMe = new char[strBuff.GetLength() + 1];
			strcpy(strMe, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strMe, 9012);
			}
				
			break;
		}

		//个人文件信息
		case 9014:
		{
			char* strFileIf = new char[strBuff.GetLength() + 1];
			strcpy(strFileIf, strBuff.GetBuffer(0));
			if(pLoad->m_hmainWndDlg)
			{
				::PostMessage(pLoad->m_hmainWndDlg, WM_MIDMSG, (WPARAM)strFileIf, 9014);
			}
			break;
		}

		case 9999:
		{
			AfxMessageBox("服务器数据库正在维护,请稍后再试!");
			break;
		}
	}
	return 0;
}

void CNetQQDlg::OnClose() 
{
	// TODO: Add your message handler code here and/or call default
	DestroyWindow();
	CDialog::OnClose();
}

void CNetQQDlg::OnBtnLogin() 
{
	// TODO: Add your control notification handler code here
	ShowWindow(false);
	CInitRegDlg* InitRegDlg = new CInitRegDlg(this);
	InitRegDlg->Create(IDD_INITREG);
	InitRegDlg->ShowWindow(true);
}

CClntSock& CNetQQDlg::GetCClntSock()
{
	return m_ClntSock;
}

void CNetQQDlg::OnBtnExit() 
{
	// TODO: Add your control notification handler code here
	OnClose();
}

void CNetQQDlg::OnBtnClose() 
{
	// TODO: Add your control notification handler code here
	OnClose();
}

void CNetQQDlg::OnBtnMin() 
{
	// TODO: Add your control notification handler code here
	PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
}

void CNetQQDlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x,point.y));	
	CDialog::OnLButtonDown(nFlags, point);
}


void CNetQQDlg::DelClentList()
{
	//清空m_pClntList链表
	tagClientInfo* pTmp;
	POSITION pos = m_pClntList.GetHeadPosition();
	for(int i = 0; i < m_pClntList.GetCount(); i++)
	{
		pTmp =  m_pClntList.GetNext(pos);

		if(pTmp->m_hChatWnd)	/*dong 12-17*/
		{
			::SendMessage(pTmp->m_hChatWnd, WM_CLOSE, 0, 0);
		}
		if(pTmp->m_hUserInfoWnd) /*dong 12-17*/
		{
			::SendMessage(pTmp->m_hUserInfoWnd, WM_CLOSE, 0, 0);
		}
		delete pTmp;
	}

	m_pClntList.RemoveAll();
}

/*---------------------------------------------------------------------------
 成功登陆	dong 12-17
 --------------------------------------------------------------------------*/
void CNetQQDlg::OnLoadInMainDlg(WPARAM wParam, LPARAM lParam)
{
	//界面切换到用户列表界面
	ShowWindow(FALSE);
	CMainDlg* dlgMainDlg = new CMainDlg(this);
	dlgMainDlg->Create(IDD_MAINDLG);
	m_hmainWndDlg = dlgMainDlg->m_hWnd;
	
	////////////////////////////////////////////////////////////////
	//添加之前登陆的用户
	tagClientInfo* pTemp;
	POSITION pos = m_pClntList.GetHeadPosition();
	for(int i = 0; i < m_pClntList.GetCount(); i++)
	{
		pTemp = m_pClntList.GetNext(pos);
		if(pTemp->m_strUsrId != m_strUserId)
		{
			CString strUserIf = pTemp->m_strUsrName + "[" + pTemp->m_strUsrId + "]";
			int nFaceIndex = atoi(pTemp->m_strFace);
			dlgMainDlg->m_lstUserList.InsertItem(i, strUserIf, nFaceIndex);
		}
	}
	
	dlgMainDlg->ShowWindow(true);
}


/*---------------------------------------------------------------------------
 获取互斥对象	dong 12-17
 --------------------------------------------------------------------------*/
HANDLE CNetQQDlg::GetMutex()
{
	return m_hMutex;
}

BOOL CNetQQDlg::PreTranslateMessage(MSG* pMsg) 
{
	// TODO: Add your specialized code here and/or call the base class
	if(m_ttToolTip.GetToolTip().m_hWnd)
		m_ttToolTip.GetToolTip().RelayEvent(pMsg);
	return CDialog::PreTranslateMessage(pMsg);
}

void CNetQQDlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	m_ttToolTip.AddToolTip("最小化窗口", GetDlgItem(IDC_BTN_MIN));
	m_ttToolTip.AddToolTip("关闭窗口", GetDlgItem(IDC_BTN_CLOSE));
	CDialog::OnMouseMove(nFlags, point);
}

void CNetQQDlg::OnBtnL() 
{
	// TODO: Add your control notification handler code here
	CWnd* pWnd = GetFocus();
	if(pWnd == GetDlgItem(IDC_BTN_EXIT))
	{
		OnClose();
	}
	else if(pWnd == GetDlgItem(IDC_BTN_LOGIN))
	{
		OnBtnLogin();
	}
	else
	{
		OnBtnLoad();
	}
}

⌨️ 快捷键说明

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