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

📄 rtp_ce_dlg.cpp

📁 分别能运行在手机和电脑上的环境的一个有关audio的源码
💻 CPP
字号:
// RTP_CEDlg.cpp : 实现文件
//

#include "stdafx.h"
#include "RTP_CE.h"
#include "RTP_CE_Dlg.h"
#include "AVClass.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#endif

AVClass *avclass=new AVClass();//自定义功能类

CMyRTP_CEDlg::CMyRTP_CEDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMyRTP_CEDlg::IDD, pParent)
{
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMyRTP_CEDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}

BEGIN_MESSAGE_MAP(CMyRTP_CEDlg, CDialog)
#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
	ON_WM_SIZE()
#endif
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_StartTalk, &CMyRTP_CEDlg::OnBnClickedStarttalk)
	ON_BN_CLICKED(IDC_StopTalk, &CMyRTP_CEDlg::OnBnClickedStoptalk)
	ON_BN_CLICKED(IDC_Exit, &CMyRTP_CEDlg::OnBnClickedExit)
END_MESSAGE_MAP()


// CMyRTP_CEDlg 消息处理程序



#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CMyRTP_CEDlg::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
	DRA::RelayoutDialog(
		AfxGetInstanceHandle(), 
		this->m_hWnd, 
		DRA::GetDisplayMode() != DRA::Portrait ? 
			MAKEINTRESOURCE(IDD_MYRTP_CE_DIALOG_WIDE) : 
			MAKEINTRESOURCE(IDD_MYRTP_CE_DIALOG));
}
#endif


int local_port;//本地端口
BOOL CMyRTP_CEDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

    SetWindowPos(&wndTopMost,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE);//设置顶层窗口
	//--------------取得本地IP
    BYTE   *p;    
    char   temp[100];    
    struct   hostent   *hp;  
	CString tmp_remote_ip;
    if(gethostname(temp,   sizeof(temp))==   0)  
    {  
		if((hp   =gethostbyname(temp))!=0)  
		{  
			p   =(BYTE   *)hp->h_addr;    
			tmp_remote_ip.Format(L"%d.%d.%d.%d",p[0],   p[1],   p[2],   p[3]);
			GetDlgItem(IDC_LOCAL_IP)->SetWindowTextW(tmp_remote_ip);
			//m_LocalIP.SetWindowTextW(tmp_remote_ip);//设置控件显示本地IP地址
			//-----------取得本地开发端口
			local_port=p[3]*p[3];//端口为IP尾段的平方
			CString tmp_port;
			tmp_port.Format(L"%d",local_port);
			GetDlgItem(IDC_LOCAL_PORT)->SetWindowTextW(tmp_port);
		}  
	}   


	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
void CMyRTP_CEDlg::OnBnClickedStoptalk()
{
	avclass->FreeAV();//关闭音频

}

void CMyRTP_CEDlg::OnBnClickedStarttalk()
{
	//--------方便系统测试
    GetDlgItem(IDC_REMOTE_IP)->SetWindowTextW(L"172.19.37.13");

	//--------取得对方IP
	CString remote_ip;
	GetDlgItem(IDC_REMOTE_IP)->GetWindowTextW(remote_ip);

	//--------计算对方的端口
	CString tmp_remote_port(remote_ip);
	int i=tmp_remote_port.Find('.',remote_ip.GetLength()-4);
	tmp_remote_port.Delete(0,i+1);//取得对方IP的尾段IP
	int remote_port=_ttoi(tmp_remote_port);
    remote_port*=remote_port;//端口为IP尾段的平方

	tmp_remote_port.Format(L"%d",remote_port);//数字转换字符串
	GetDlgItem(IDC_REMOTE_PORT)->SetWindowTextW(tmp_remote_port);//显示对方端口号

	
	avclass->InitAV(this,local_port,remote_ip,remote_port);//初始化音频

}


void CMyRTP_CEDlg::OnBnClickedExit()
{
	::SendMessage(m_hWnd,WM_CLOSE,0,0);
}

⌨️ 快捷键说明

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