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

📄 tvmeetingdlg.cpp

📁 用c++做的视频会议源代码
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// TVMeetingDlg.cpp : implementation file

#include "stdafx.h"
#include "TVMeeting.h"
#include "TVMeetingDlg.h"
#include "IniFile.h"
#include "IpDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
#include <winsock.h>
#include "thread.h"
#include "ClientInfo.h"
#include "g729a.h"
CTVMeetingDlg* pDlgInst=0;


class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CTVMeetingDlg dialog

CTVMeetingDlg::CTVMeetingDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CTVMeetingDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CTVMeetingDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
	m_hCmdSockThread=NULL;
	m_hAVSockThread=NULL;

	m_idCmd=0;
	pDlgInst=this;	
	m_uDataSend=0;
	m_iAudioBuf=0;
	m_nLogInfoLines=500;
	sIP[0]="";
	sIP[1]="";
	sIP[2]="";
	PortBusy[0]=0;
	PortBusy[1]=0;
	PortBusy[2]=0;
	m_nDistributePort1=0;
	m_nDistributePort2=0;
	m_nDistributePort3=0;
	bIsPortChecking=false;
	DistributeIP[0]="";
	DistributeIP[1]="";
	DistributeIP[2]="";
	PlayFlag[0]=0;
	PlayFlag[1]=0;
	PlayFlag[2]=0;
	m_Count[0]=0;
	m_Count[1]=0;
	m_Count[2]=0;
}

void CTVMeetingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CTVMeetingDlg)
	DDX_Control(pDX, IDC_JOIN_LIST, m_LstJoin);
	DDX_Control( pDX, IDC_SLD_AUDIO,   m_mainVolume );

	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CTVMeetingDlg, CDialog)
	//{{AFX_MSG_MAP(CTVMeetingDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_JOIN, OnJoin)
	ON_BN_CLICKED(IDC_EXIT, OnExit)
	ON_WM_DESTROY()
	ON_WM_TIMER()
	ON_BN_CLICKED(IDC_MAIN_VIDEO, OnMainVideo)
	ON_BN_CLICKED(IDC_SEND_TEXT, OnSendText)
	ON_WM_LBUTTONDBLCLK()
	ON_BN_CLICKED(IDC_SEND1, OnSend1)
	ON_BN_CLICKED(IDC_SEND2, OnSend2)
	ON_BN_CLICKED(IDC_JOIN3, OnJoin3)
	ON_BN_CLICKED(IDC_SetUp, OnSetUp)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

BOOL CTVMeetingDlg::OnInitDialog()
{
	CDialog::OnInitDialog();
	::SetProp(m_hWnd, szWindowProp, (HANDLE)1);
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);

		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
		CString strOnTop;
		strOnTop.LoadString(IDS_ONTOP);

		if ( !strOnTop.IsEmpty() )
		{
			pSysMenu->AppendMenu(MF_STRING,IDM_ONTOP,strOnTop);
		}
	}

	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon

	// TWSCRIPTEDIT	->
	static LPCTSTR szKeywords = " Call Local ";

	static LPCTSTR szConstants = " ";
	// <- TWSCRIPTEDIT	


	m_EditMain.SubclassDlgItem(IDC_LOG_INFO, this);
	m_EditMain.Initialize();

	m_EditMain.SetCaseSensitive(FALSE);
	m_EditMain.SetStringQuotes(_T("*"));
	m_EditMain.SetSLComment(_T('@'));
	m_EditMain.SetSLComment(_T("vbRem"));

	m_EditMain.AddKeywords(szKeywords);
	m_EditMain.AddConstants(szConstants);

	//Set Window Position
	::SetWindowPos(GetDlgItem(IDC_VLocal)->m_hWnd,0,0,0,176,144,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_VOne)->m_hWnd,0,0,0,176,144,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_VTwo)->m_hWnd,0,0,0,176,144,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_VThree)->m_hWnd,0,0,0,176,144,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_VMain)->m_hWnd,0,0,0,352,288,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_LOG_INFO)->m_hWnd,0,0,0,352,133,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_TXTSEND)->m_hWnd,0,0,0,305,23,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_NLocal)->m_hWnd,0,0,0,176,18,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_NOne)->m_hWnd,0,0,0,176,18,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_NTwo)->m_hWnd,0,0,0,176,18,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_NThree)->m_hWnd,0,0,0,176,18,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SEND_TEXT)->m_hWnd,0,0,0,39,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_MAIN_VIDEO)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SetUp)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_JOIN)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_EXIT)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SEND1)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SEND2)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_JOIN3)->m_hWnd,0,0,0,68,24,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SLD_PHONE)->m_hWnd,0,0,0,117,20,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SLD_AUDIO)->m_hWnd,0,0,0,117,20,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_CONTROL)->m_hWnd,0,0,0,173,110,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_MENU)->m_hWnd,0,0,0,173,110,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_MIC)->m_hWnd,0,0,0,16,16,SWP_NOMOVE);
	::SetWindowPos(GetDlgItem(IDC_SP)->m_hWnd,0,0,0,16,16,SWP_NOMOVE);


	CString ssIP;
	char pIni[100];
	char sPath[100];
	strcpy(pIni,IniFile.pIniFileName);
	path=IniFile.GetIniFilePath(pIni);
	strcpy(sPath,path.GetBuffer(path.GetLength()));
	CString stmpIP[MAX_CONNECT_USER];
	int j=0;
	for (int i=0;i<MAX_CONNECT_USER;i++)
	{
		CString sSection;
		sSection.Format("IP%d",i+1);
		ssIP=IniFile.GetIniStr("IPADDRESS",sSection,path);
		ssIP.TrimLeft();
		ssIP.TrimRight();
		if (ssIP!=m_szLocalIP && ssIP!="")
		{
			sIP[j]=ssIP;
			m_ChatNo[j]=j+1;
			j++;
		}
	}
	
	// added by rc 04031611
	InitializeCriticalSection(&m_cs);
	for (int n =0 ;n<3;n++)
	{
		ui[n].bUsed=FALSE;
		ui[n].id=n;
	}

	bMainExist=FALSE;
	MainExist=NULL;
	uiCount=0;
	SLocal=(CStatic *)GetDlgItem(IDC_VLocal);
	
	int nRetCode;
	nRetCode = StartUp();
	TRACE1("StartUp RetCode: %d\n", nRetCode);
	nRetCode = GetLocalHostName(m_sHostName);
	TRACE1("GetLocalHostName RetCode: %d\n", nRetCode);
	nRetCode = GetIPAddress(m_sHostName, m_sIPAddress);
	m_szLocalIP=m_sIPAddress;
	TRACE1("GetIPAddress RetCode: %d\n", nRetCode);
	nRetCode = CleanUp();
	TRACE1("CleanUp RetCode: %d\n", nRetCode);

	ZeroMemory(m_AudioRemote,SIZE_AUDIO_FRAME);
	ZeroMemory(m_AudioRemote2,SIZE_AUDIO_FRAME);
	ZeroMemory(m_AudioRemote3,SIZE_AUDIO_FRAME);
	ZeroMemory(m_AudioPlayFrame,SIZE_AUDIO_FRAME);

	
	InitializeSocket();
	DestroySocket(SOCK_CMD);
	DestroySocket(SOCK_AV);
	DestroySocket(SOCK_AUDIO_REC1);
	DestroySocket(SOCK_AUDIO_REC2);
	DestroySocket(SOCK_AUDIO_REC3);

	CString s;
	if(!InitSocket(SOCK_CMD))
	{
		s.Format("Init Socket %d error!",PORT);
		UpdateStatusBarInfo(s);
	}
	else
	{
		s.Format("Init Socket %d Successfully!",PORT);
		UpdateStatusBarInfo(s);
	}
	if(!InitSocket(SOCK_AV))
	{
		s.Format("Init Socket %d Error!",PORT+1);
		UpdateStatusBarInfo(s);
	}
	else
	{
		s.Format("Init Socket %d Successfully!",PORT+1);
		UpdateStatusBarInfo(s);
	}
	InitAV();
	if(!InitSocket(SOCK_AUDIO_REC1))
	{
		s.Format("Init Socket %d Error!",PORT+11);
		UpdateStatusBarInfo(s);
	}
	else
	{
		s.Format("Init Socket %d Successfully!",PORT+11);
		UpdateStatusBarInfo(s);
	}
	if(!InitSocket(SOCK_AUDIO_REC2))
	{
		s.Format("Init Socket %d Error!",PORT+12);
		UpdateStatusBarInfo(s);
	}
	else
	{
		s.Format("Init Socket %d Successfully!",PORT+12);
		UpdateStatusBarInfo(s);
	}
	if(!InitSocket(SOCK_AUDIO_REC3))
	{
		s.Format("Init Socket %d Error!",PORT+13);
		UpdateStatusBarInfo(s);
	}
	else
	{
		s.Format("Init Socket %d Successfully!",PORT+13);
		UpdateStatusBarInfo(s);
	}
	
	m_mainVolume.Init( MIXERLINE_COMPONENTTYPE_DST_SPEAKERS,
	                   NO_SOURCE,
	                   MIXERCONTROL_CONTROLTYPE_VOLUME, 
					   CMixerFader::MAIN );
	m_mikeVolume.SubclassDlgItem( IDC_SLD_PHONE, this );
	m_mikeVolume.Init( MIXERLINE_COMPONENTTYPE_DST_WAVEIN,
	                   MIXERLINE_COMPONENTTYPE_SRC_MICROPHONE,
					   MIXERCONTROL_CONTROLTYPE_VOLUME, 
					   CMixerFader::MAIN );	

	//AfxBeginThread(ComputeThreadClientSocket,GetSafeHwnd(),THREAD_PRIORITY_NORMAL);	
	//g_eventStart.SetEvent();
    

	// CG: The following block was added by the ToolTips component.
	{
		// Create the ToolTip control.
		m_tooltip.Create(this);
		m_tooltip.Activate(TRUE);

		// TODO: Use one of the following forms to add controls:
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), <string-table-id>);
		// m_tooltip.AddTool(GetDlgItem(IDC_<name>), "<text>");
		CString strTips;

		strTips.LoadString(IDS_TipTextShow);
		m_tooltip.AddTool(GetDlgItem(IDC_LOG_INFO), strTips);

		strTips.LoadString(IDS_TipTextOut);
		m_tooltip.AddTool(GetDlgItem(IDC_TXTSEND), strTips);

		strTips.LoadString(IDS_TipMainVideo);
		m_tooltip.AddTool(GetDlgItem(IDC_MAIN_VIDEO), strTips);

		strTips.LoadString(IDS_TipExit);
		m_tooltip.AddTool(GetDlgItem(IDC_EXIT), strTips);

		strTips.LoadString(IDS_TipConnect);
		m_tooltip.AddTool(GetDlgItem(IDC_JOIN), strTips);

		strTips.LoadString(IDS_TipSend);
		m_tooltip.AddTool(GetDlgItem(IDC_SEND_TEXT), strTips);

		strTips.LoadString(IDS_TipUserList);
		m_tooltip.AddTool(GetDlgItem(IDC_JOIN_LIST), strTips);

		strTips.LoadString(IDS_TipConnect);
		m_tooltip.AddTool(GetDlgItem(IDC_SEND1), strTips);

		strTips.LoadString(IDS_TipConnect1);
		m_tooltip.AddTool(GetDlgItem(IDC_SEND2), strTips);

		strTips.LoadString(IDS_TipConnect2);
		m_tooltip.AddTool(GetDlgItem(IDC_JOIN3), strTips);
		
		strTips.LoadString(IDS_TipSetUp);
		m_tooltip.AddTool(GetDlgItem(IDC_SetUp), strTips);
		
		strTips.LoadString(IDS_TipAudio);
		m_tooltip.AddTool(GetDlgItem(IDC_SLD_AUDIO), strTips);

		strTips.LoadString(IDS_TipMic);
		m_tooltip.AddTool(GetDlgItem(IDC_SLD_PHONE), strTips);
	}
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CTVMeetingDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}

	////////////////////////////////////////////////////////////////////
	// added by rc
	// Function : Determin The On Top Menu Item State To Set The Window Position
	/////////////////////////////////////////////////////////////////////
	else if ( (nID &0xFFF0) == IDM_ONTOP )
	{
		CMenu* pSysMenu = GetSystemMenu(FALSE);
		if ( (pSysMenu->GetMenuState(nID,MF_BYCOMMAND)) == MF_UNCHECKED )
		{
			pSysMenu->CheckMenuItem(nID,MF_CHECKED);
			SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
		}
		else if ( (pSysMenu->GetMenuState(nID,MF_BYCOMMAND)) == MF_CHECKED )
		{
			pSysMenu->CheckMenuItem(nID,MF_UNCHECKED);
			SetWindowPos(&wndNoTopMost,0,0,0,0,SWP_NOSIZE|SWP_NOMOVE);
		}
	}
	////////////////////////End added by rc////////////////////////////////
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CTVMeetingDlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

//  The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CTVMeetingDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CTVMeetingDlg::OnOK() // added by rc
{
}

void CTVMeetingDlg::OnCancel() // added by rc
{
}

void CTVMeetingDlg::OnClose() // added by rc
{
	if (::MessageBox(m_hWnd,"Do you want to Quit really?","TVMeeting",MB_YESNO|MB_ICONQUESTION )==IDYES)	
	{
		POSITION pos;
		if (m_ClientInfoList.GetCount()!=0)
		{
			TRACE1("List Number : %d ",m_ClientInfoList.GetCount());
			////////////////////////////////////////////////
			for( pos = m_ClientInfoList.GetHeadPosition(); pos != NULL; )
			{				
				CClientInfo *pClientInfo=m_ClientInfoList.GetAt(pos);
				if (pClientInfo!=NULL)
				{
					CString strIP;
					strIP.Format("%d.%d.%d.%d",
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b1,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b2,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b3,
						pClientInfo->m_Cmddst.sin_addr.S_un.S_un_b.s_b4);
					char szIP[20];
					strcpy(szIP,strIP.GetBuffer(strIP.GetLength()));
					/////////////////////////////////////////////////////////////////
					PACK_CMD pc;
					pc.flag=FLAG_CMD; // WZZ 2003-4-3
					pc.data_size_extra=0;
					SetCmdDst(szIP,PORT);
					m_sockaddr=GetCurrentAddr();
					pc.cmd=CMD_EXIT;
					pc.ext=VER_TVMEETING&0xff;
					pc.type=0;
					pc.id=m_idCmd++;
					m_CMDSocket.SendTo((char*)&pc,sizeof(pc),(sockaddr*)&m_Cmddst);

					/////////////////////////////////////////////////////////////////

					pClientInfo=NULL;
					delete pClientInfo;
				}
				m_ClientInfoList.GetNext(pos);
			}// enf of for

⌨️ 快捷键说明

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