上位机MFC实现带语音功能聊天室源代码
运行例程, 可以建立服务器当服务器使用。
也可以连接服务器,当客户端使用。
界面如上图。
语音聊天按钮源代码:
- void CExample2_ChatRoomDlg::OnSound()
- {
- // TODO: Add your control notification handler code here
- if(m_bInit==false)
- {
- AfxMessageBox("Please Prepare the Network");
- return;
- }
- static BOOL issend=TRUE;
- CString ip;
- BYTE f0,f1,f2,f3;
- ((CIPAddressCtrl *)(GetDlgItem(IDC_IPADDRESS)))->GetAddress(f0,f1,f2,f3);
- ip.Format("%d.%d.%d.%d",f0,f1,f2,f3);
- int port=GetDlgItemInt(IDC_PORT);
- typedef long _stdcall SETIP(char *);
- typedef void _stdcall SETPORT(int);
- typedef void _stdcall STARTSOUND();
- typedef void _stdcall STOPSOUND();
- static HINSTANCE sound=LoadLibrary("../Sound/Sound.dll");
- if(issend)
- {
- if(sound!=NULL)
- {
- SETIP *setip=(SETIP*)GetProcAddress(sound,"setIpAddr");
- SETPORT *setport=(SETPORT*)GetProcAddress(sound,"setPort");
- STARTSOUND *start=(STARTSOUND*)GetProcAddress(sound,"SoundStart");
- setport(port);
- if(setip(ip.GetBuffer(0)))
- {
- start();
- SetDlgItemText(IDC_SOUND,"停止语音聊天");
- issend=FALSE;
- ip.ReleaseBuffer();
- }
- else
- {
- AfxMessageBox("Cannot connect to the server");
- FreeLibrary(sound);
- return;
- }
- }
- else
- {
- AfxMessageBox("Error Loading the sound.dll");
- }
- }
- else
- {
- if(sound!=NULL)
- {
- STOPSOUND *stop= (STOPSOUND*)GetProcAddress(sound,"SoundStop");
- stop();
- FreeLibrary(sound);
- }
- SetDlgItemText(IDC_SOUND,"开始语音聊天");
- issend=TRUE;
- }
- }
复制代码 源代码下载:
上位机VC MFC程序开发精典实例大全源码与视频讲解配套下载408例 经历1年的编程与录制点击进入查看
如果您认可,可联系功能定制! 如果您着急,充值会员可直接联系发您资料!
|