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

📄 rtcoutgoingdlg.cpp

📁 再贡献一份基于osip 协议栈的用户代理
💻 CPP
📖 第 1 页 / 共 5 页
字号:
/******************************************************>
 * Copyright (c) 2001 Microsoft Corporation. 
 * All rights reserved.
 *
 * Copyright (c) 2005 enum.at
 * All rights reserved.
 *
 * @Abstract: RTCOutGoingDlg.cpp
 * ---------- [ Source Definition File]
 *
 * 
 * @Description :
 * -------------
 * Class Declaration file for the Main RTCOutgoing Dialog Box
 * this Class will contain the state machine transitions
 * of the RTC Core Sample,creating PC-PC,PC-PH,PH-PH calls, 
 * receiving events disconnected calls, displaying video 
 * starting T120 App Sharing and Starting the Tunning Wizard
 *
 *
 ******************************************************/

#define ALL_ENUM_SERVICES _T("sip|h323|x-skype:callto|voice:sip|voice:h323|voice:tel|video:sip|video:h323|video:tel|email:mailto|fax:tel|sms:tel|sms:sip|sms:sips|sms:mailto|ems:tel|ems:sip|ems:sips|ems:mailto|mms:tel|mms:sip|mms:sips|mms:mailto|ifax:mailto|web:http|web:https|ft:ftp|pres|ann:sip|ann:h323|ann:tel|ann:http|ann:ftp|enum|void:mailto|void:http|void:mailto|loc:http|key:ldap|key:http")

#include "stdafx.h"
#include "RTCOutgoing.h"
#include "RTCOutgoingDlg.h"
#include ".\rtcoutgoingdlg.h"

#include <string>
#include <boost/regex.hpp>

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


/**********************************************************
//@Class CAboutDlg 
//
//@Description
//  
//  About Dialog Box
//
//
//
//*********************************************************/

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()
//
//@Description
//  
//  Constructor
//
//@Args In:     Void
//@Args Out:    Void
//
//
//*********************************************************/
CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}


/**********************************************************
//@DoDataExchange()
//
//@Description
//  
//
//@Args In:     CDataExchange *
//@Args Out:    Void
//
//
//*********************************************************/
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}



/**********************************************************
//@CAboutDlg Message Map
//
//@Description
//  
//
//
//*********************************************************/

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()




/**********************************************************
//@Class CRTCOutgoingDlg
//
//
//
//*********************************************************/


CRTCOutgoingDlg::CRTCOutgoingDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CRTCOutgoingDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CRTCOutgoingDlg)

	m_pIRTCClient    = NULL;
	m_pIRTCSession   = NULL;
	m_pIRecvVideo    = NULL;
	m_pIPrevVideo    = NULL;
	m_pIRTCParty     = NULL;
	m_SessionType    = RTCST_PC_TO_PC;

	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);

	m_nLogonAttemptCount = 0;

	dlgNaptr = NULL;
}


/**********************************************************
//@DoDataExchange()
//
//@Description
//  
//
//@Args In:     CDataExchange *
//@Args Out:    Void
//
//
//*********************************************************/
void CRTCOutgoingDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CRTCOutgoingDlg)
	DDX_Control(pDX, IDC_STATUS, m_ctrlEditStatus);
	DDX_Control(pDX, IDC_DURI, m_editDURI);
	DDX_Control(pDX, IDC_TUNE, m_btnTune);
	DDX_Control(pDX, IDC_DISCONNECT, m_btnDisconnect);
	DDX_Control(pDX, IDC_CONNECT, m_btnConnect);
	DDX_Control(pDX, IDC_BUTTON_SIP, m_btnSip);
	DDX_Control(pDX, IDC_EDIT_SIP, m_editSIP);
	DDX_Control(pDX, IDC_EDIT_EMAIL, m_editEMAIL);
	DDX_Control(pDX, IDC_EDIT_WEB, m_editWEB);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_ENUM_JPRS1CTRL1, m_EnumObject);
	DDX_Control(pDX, IDC_EDIT_SIPUSER, m_editSipUser);
	DDX_Control(pDX, IDC_EDIT_SIPDOMAIN, m_editSipDomain);
	DDX_Control(pDX, IDC_EDIT_SIPPW, m_editSipPw);
	DDX_Control(pDX, IDC_EDIT_SIPOBP, m_editSipObp);
	DDX_Control(pDX, IDC_EDIT_REGISTERSTATUS, m_editRegisterStatus);
	DDX_Control(pDX, IDC_BUTTON_LOGON, m_btnLogOn);
	DDX_Control(pDX, IDC_BUTTON_LOGOFF, m_btnLogOff);
	DDX_Control(pDX, IDC_EDIT_SKYPE, m_editSKYPE);
	DDX_Control(pDX, IDC_EDIT_ENUMSTATUS, m_editEnumStatus);
	DDX_Control(pDX, IDC_CHECK_NAPTR, m_editNAPTR);
}



/**********************************************************
//@CRTCOutGoingDlg MessageMap
//
//@Description
//  
//
//
//*********************************************************/

BEGIN_MESSAGE_MAP(CRTCOutgoingDlg, CDialog)
	//{{AFX_MSG_MAP(CRTCOutgoingDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_CONNECT, OnConnect)
	ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect)
	ON_BN_CLICKED(IDC_TUNE, OnTune)
	ON_WM_CLOSE()
	ON_BN_CLICKED(IDC_BUTTON_ENUM, OnEnum)
	ON_BN_CLICKED(IDC_BUTTON_SIP, OnSip)
	ON_BN_CLICKED(IDC_BUTTON_EMAIL, OnEmail)
	ON_BN_CLICKED(IDC_BUTTON_WEB, OnWeb)
	//}}AFX_MSG_MAP
	ON_BN_CLICKED(IDC_BUTTON_LOGON, OnBnClickedButtonLogon)
	ON_BN_CLICKED(IDC_BUTTON_LOGOFF, OnBnClickedButtonLogoff)
	ON_BN_CLICKED(IDC_BUTTON_SKYPE, OnBnClickedButtonSkype)
END_MESSAGE_MAP()

/**********************************************************
//@OnInitDialog
//
//@Description
//  
//
//@Args In:     CDataExchange *
//@Args Out:    Void
//
//
//*********************************************************/
BOOL CRTCOutgoingDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	//
	//About Menu is Added to the Dialogbox
	//

	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);
		}
	}

	//
	// Icon Settings
	//

	SetIcon(m_hIcon, TRUE);			
	SetIcon(m_hIcon, FALSE);		


	::CoInitializeEx(NULL,COINIT_APARTMENTTHREADED);

	m_ctrlEditStatus.SetWindowText(_T("Initializing ..."));

	HRESULT hr = InitializeRTCApp();


	if (FAILED(hr))
	{

		LOGMSGERROR(_T("InitializeRTCApp() Failed: 0x%x"), hr);

		return FALSE;

	}


	//
	// Set the Initial States of the Control
	//


	InitialControlsState();


	// Load Values from the Registry
    WCHAR szText[MAX_STRING];
	if (RegistryGet(L"SipUser", szText) == S_OK) {
		m_editSipUser.SetWindowText(szText);
	}
	if (RegistryGet(L"SipDomain", szText) == S_OK) {
		m_editSipDomain.SetWindowText(szText);
	}
	if (RegistryGet(L"SipObp", szText) == S_OK) {
		m_editSipObp.SetWindowText(szText);
	}


	// check if Skype is installed ....
	// ckeck if callto URI handler points to Skype
	WCHAR szData[MAX_STRING];
	HKEY hKey;
	LONG lResult;
	DWORD cbSize = MAX_STRING * sizeof(WCHAR);

	lResult = RegOpenKeyW(HKEY_CLASSES_ROOT, _T("callto\\shell\\open\\command"), &hKey);

	if (lResult != ERROR_SUCCESS)
	{
		// popub windows: Can not open callto URI handler - please install Skype, Skype links will not work
		MessageBox(_T("Can not open callto URI handler. Probably Skype URIs will not work. Please (re)install Skype!"),
			_T("ENUM Softphone"));
	} else {    

		lResult = RegQueryValueExW(hKey, _T(""), NULL, NULL, (LPBYTE)szData, &cbSize);

		RegCloseKey(hKey);

		if (lResult != ERROR_SUCCESS)
		{
			// popub windows: can not read callto URI handler - please install Skype, Skype links will not work
			MessageBox(_T("Can not read callto URI handler. Probably Skype URIs will not work. Please (re)install Skype!"),
				_T("ENUM Softphone"));
		} else {

			// use regex to look for skype URI
			//std::wstring convstring (textString);

			static const boost::wregex e(L"skype", boost::regbase::icase);

			if (boost::regex_search(szData, e)) {
				m_editRegisterStatus.SetWindowText(_T("callto URI handler belongs to Skype"));
			} else {
				// popub windows: callto URI handler does not belong to Skype - please install Skype, Skype links will not work
				MessageBox(_T("callto URI handler does not belong to Skype. Probably Skype URIs will not work. Please (re)install Skype!"),
					_T("ENUM Softphone"));
			}
		}
	}
	
	return TRUE;  
}

/**********************************************************
//@OnSysCommand()
//
//@Description
//  
//
//@Args In:     UINT, LPARAM
//@Args Out:    Void
//
//
//*********************************************************/
void CRTCOutgoingDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

/**********************************************************
//@OnPaint
//
//@Description
//  
// For minimize/maximize re-painting
//
//
//@Args In:     
//@Args Out:    Void
//
//
//*********************************************************/

void CRTCOutgoingDlg::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();
	}
}


/**********************************************************
//@OnQueryDragIcon
//
//@Description
//  
//
//@Args In:     Void
//@Args Out:    HCURSOR
//
//
//*********************************************************/
HCURSOR CRTCOutgoingDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

/**********************************************************
//@UI Manipulation Methods
//*********************************************************/

/**********************************************************
//@InitlialControlsState
//
//@Description
//  
//  Setting the UI Controls to their initial State
//
//
//@Args In:     Void
//@Args Out:    Void
//
//
//*********************************************************/
void 
CRTCOutgoingDlg::InitialControlsState()
{

	HRESULT   hr  = S_OK;
	//
	// Disable Buttons that should not be functional
	//

	StateDisconnectIDC(VARIANT_FALSE);
	StateConnectIDCVisible(VARIANT_TRUE);
	StateLogOffIDC(VARIANT_FALSE);

	RedrawWindow();
}

/**********************************************************
//@StateConnectIDO
//
//@Description
//   
//  Disabled/Enables the Connect Button
//
//@Args In:     Void
//@Args Out:    Void
//
//
//*********************************************************/
void 
CRTCOutgoingDlg::StateConnectIDC(VARIANT_BOOL fEnable)
{
	if (VARIANT_TRUE == fEnable)
	{
		m_btnConnect.ModifyStyle( WS_DISABLED , 0 , 0);
		RedrawWindow();

	}
	else
	{
		m_btnConnect.ModifyStyle( 0 , WS_DISABLED , 0);
		RedrawWindow();
	}
}


//klaus

/**********************************************************
//@StateConnectIDC
//  Disabled/Enables the Log On Button
//*********************************************************/
void 
CRTCOutgoingDlg::StateLogOnIDC(VARIANT_BOOL fEnable)
{
	if (VARIANT_TRUE == fEnable)
	{
		m_btnLogOn.ModifyStyle( WS_DISABLED , 0 , 0);
		RedrawWindow();

	}
	else
	{
		m_btnLogOn.ModifyStyle( 0 , WS_DISABLED , 0);
		RedrawWindow();
	}
}

/**********************************************************
//@StateConnectIDC
//  Disabled/Enables the Log On Button
//*********************************************************/
void 
CRTCOutgoingDlg::StateLogOffIDC(VARIANT_BOOL fEnable)
{
	if (VARIANT_TRUE == fEnable)
	{
		m_btnLogOff.ModifyStyle( WS_DISABLED , 0 , 0);
		RedrawWindow();

	}
	else
	{
		m_btnLogOff.ModifyStyle( 0 , WS_DISABLED , 0);
		RedrawWindow();
	}
}


void 
CRTCOutgoingDlg::StateSipIDC(VARIANT_BOOL fEnable)
{
	if (VARIANT_TRUE == fEnable)
	{
		m_btnSip.ModifyStyle( WS_DISABLED , 0 , 0);
		RedrawWindow();

	}
	else
	{
		m_btnSip.ModifyStyle( 0 , WS_DISABLED , 0);
		RedrawWindow();
	}
}
// end klaus


/**********************************************************
//@StateConnectIDOVisible
//
//@Description
//   
//  Disabled/Enables the Connect Button
//
//@Args In:     Void
//@Args Out:    Void
//
//
//*********************************************************/
void 
CRTCOutgoingDlg::StateConnectIDCVisible(VARIANT_BOOL fVisible)
{
	if (VARIANT_TRUE == fVisible)
	{
		m_btnConnect.ModifyStyle(  0 , WS_VISIBLE , 0);
		RedrawWindow();

	}
	else
	{
		m_btnConnect.ModifyStyle( WS_VISIBLE , 0 , 0);
		RedrawWindow();
	}
}

⌨️ 快捷键说明

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