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

📄 voipdemo.cpp

📁 Windows CE .Net 下面 VOIP编程的经典实例。对于初学Windows 平台下VOIP编程技术的程序员颇具借鉴意义!
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	
	if (lvi.iItem < 0) {
		lvi.iItem = ListView_FindItem(m_hwndOfflineView, LISTVIEW_BEGIN, &lvif);
		
		if (lvi.iItem < 0) {
			// should we then add the buddy to the list view?  Or add him as a buddy?
			// what happens when someone has us as a watcher, yet we have no buddy status on them?
			DEBUGMSG( 1, (L"Voipdemo: Error: Status change for buddy not found in the listview\r\n" ) );
			return;
		}

		hwndCurrentList = m_hwndOfflineView;

		// buddy is in offline view, do we need to change him to online?
		if (eNewStat != ES_OFFLINE) {
			bChangeLists = TRUE;
			hwndDestList = m_hwndOnlineView;
		}			
	} else {
		hwndCurrentList = m_hwndOnlineView;		
		
		// buddy's currently in the online view.  Do we need to change him to offline?
		if (eNewStat == ES_OFFLINE) {
			bChangeLists = TRUE;
			hwndDestList = m_hwndOfflineView;
		}
	}	

	// is the buddy selected?  We need to know in case we're moving the buddy to a different list
	BOOL bSelected = FALSE;
	if (m_cSelectedBuddy.pBuddy == pBuddy) 
		bSelected = TRUE;

	if (bChangeLists) {
		// delete from current list, re-insert to new list
		if (bSelected) {
			// de-select item
			ListView_SetItemState(hwndCurrentList, lvi.iItem, 0, LVIS_SELECTED);	
		}

		// removing item, addref so that it's not lost!  (removing an item from our listview will de-ref it
		pBuddy->AddRef();
		ListView_DeleteItem(hwndCurrentList, lvi.iItem);
		lvi.iItem = ListView_InsertItem(hwndDestList, &lvi);
		
		if (bSelected) {
			// re-select item
			ListView_SetItemState(hwndDestList, lvi.iItem, LVIS_SELECTED, LVIS_SELECTED);
		}
	} else {
		ListView_SetItem(hwndCurrentList, &lvi);
		m_cSelectedBuddy.eStat = (m_cSelectedBuddy.pBuddy == pBuddy) ? eNewStat : m_cSelectedBuddy.eStat;
	}	
}

/************************************************************************************************

  CleanupListViews

	Perform any necessary cleanup of the listviews. Notably, destroy the font used to display 
	listview items.

 ************************************************************************************************/

VOID
CleanupListViews()
{
	// delete the handle to the font used by the listviews (make sure they don't use it afterwards, in case of cleanup issues)

	if ( m_hwndOnlineView )
		SendMessage( m_hwndOnlineView, WM_SETFONT, NULL, FALSE );
	if ( m_hwndOfflineView )
		SendMessage( m_hwndOfflineView, WM_SETFONT, NULL, FALSE );
	if (m_hFont)
		DeleteObject(m_hFont);		
}

/************************************************************************************************

  FormCalleeAryListView

	Build a PARTICIPANT_INFO array from the presently selected buddies.  This call is in place
	to support PHONE_TO_PHONE calls which are presently not supported, so it has not been fully 
	tested

 ************************************************************************************************/

BOOL
FormCalleeAryListView(PARTICIPANT_INFO*** pppPart, int* numParticipants) {
	// determine the number of selected buddies, form the array for the callees
	
	*pppPart = new PARTICIPANT_INFO*[m_cSelectedBuddy.iSelectedBuddies];
	
	*numParticipants = m_cSelectedBuddy.iSelectedBuddies;
	ASSERT( ListView_GetSelectedCount(m_hwndOnlineView) == (UINT) m_cSelectedBuddy.iSelectedBuddies);

	BOOL bFailed = FALSE;
	IRTCBuddy* pBuddy;
	LVITEM lvi;
	ZeroMem(lvi);
	lvi.mask = LVIF_PARAM;
	lvi.iItem = LISTVIEW_BEGIN; // start the search for selected items at the beginning of the listview

	for (int i = 0; i < m_cSelectedBuddy.iSelectedBuddies; i++) {
		// find the next guy in the listview and store him in the array
		lvi.iItem = ListView_GetNextItem(m_hwndOnlineView, lvi.iItem, LVNI_SELECTED);
		
		if (ListView_GetItem(m_hwndOnlineView, &lvi) == FALSE) {
			DEBUGMSG( 1, (L"Voipdemo: FormCalleeAryListView() Error!  Unable to get the next selected buddy from the listview.\r\n") );
			// bad error, can't finish
			bFailed = TRUE;
			break;
		}
		
		pBuddy = (IRTCBuddy*)lvi.lParam;
		
		*(*pppPart + i) = new PARTICIPANT_INFO(NULL, NULL, pBuddy, BT_PHONE);
		
		BSTR bstrName = NULL;
		BSTR bstrAddr = NULL;
		
		pBuddy->get_Name(&bstrName);
		pBuddy->get_PresentityURI(&bstrAddr);
		
		// already SysAlloc'ed for us, don't re-alloc
		((*pppPart)[i])->put_Name(bstrName, NO_ALLOC);
		((*pppPart)[i])->put_Addr(bstrAddr, NO_ALLOC);
	}

	if (bFailed) {
		// some kind of error, cleanup everything
		for (int j = i; j > -1; j--)	
			delete (*pppPart)[j];
		delete[] *pppPart;
		*pppPart = NULL;
		*numParticipants = 0;
		return FALSE;
	}

	// all set to go
	return TRUE;
}





//
//								Dialog Window Procedures
//





// Mesage handler for the About box
LRESULT CALLBACK Proc_About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	RECT rt1;

	switch (message)
	{
		case WM_INITDIALOG:
			// trying to center the dialog			
			if ( GetWindowRect( hDlg, &rt1 ) )
			{
				CenterDialog( hDlg, rt1);
			}
			return TRUE;

		case WM_COMMAND:
			if ((LOWORD(wParam) == IDOK) || (LOWORD(wParam) == IDCANCEL))
			{
				EndDialog(hDlg, LOWORD(wParam));
				return TRUE;
			}
			break;
	}
    return FALSE;
}


// Mesage handler for the Add contact box
LRESULT CALLBACK Proc_AddBuddy(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	RECT rt1;
	
	switch (message)
	{
	case WM_INITDIALOG:
		// trying to center the dialog
		if ( GetWindowRect( hDlg, &rt1 ) )
		{
			CenterDialog(hDlg, rt1);	
		}
		
		SendDlgItemMessage( hDlg, IDC_NAMEEDIT, EM_LIMITTEXT, MAINWND_BUDDYTXTLENGTH, 0 );
		SendDlgItemMessage( hDlg, IDC_IPEDIT, EM_LIMITTEXT, MAINWND_BUDDYTXTLENGTH, 0 );		
		SendDlgItemMessage( hDlg, IDC_RADIO1, BM_SETCHECK, BST_CHECKED, 0 );
		
		return TRUE;
		
	case WM_COMMAND:
		if ( (LOWORD( wParam ) == IDCANCEL ) )
		{
			EndDialog( hDlg, LOWORD( wParam ) );
			return TRUE;
		}
		
		if ( ( LOWORD( wParam ) == IDOK ) )
		{
			TCHAR szName[ MAINWND_BUDDYTXTLENGTH + 4 ];
			TCHAR szAddr[ MAINWND_BUDDYTXTLENGTH + 4 ];
			GetDlgItemText( hDlg, IDC_NAMEEDIT, szName, sizeof( szName )/sizeof( TCHAR ) );
			GetDlgItemText( hDlg, IDC_IPEDIT, szAddr, sizeof( szAddr )/sizeof( TCHAR ) );
			
			if ( *szName == '\0' )
			{
				MessageBox( NULL, NO_USER_NAME_MSG,	L"Error", MB_OK );
				SetFocus( GetDlgItem( hDlg, IDC_NAMEEDIT ) );
				
				return FALSE;
			}
			
			BUDDYTYPE bt = BT_COMPUTER;
			if ( SendDlgItemMessage( hDlg, IDC_RADIO1, BM_GETCHECK, 0, 0 ) != BST_CHECKED )
				bt = BT_PHONE;
			
			ESTATUS esStat = (bt == BT_COMPUTER) ? ES_OFFLINE : ES_ONLINE;
			
			if ( *szAddr == '\0') {
				if (bt != BT_PHONE)	{					
					MessageBox( NULL, NO_SIP_ADDR_MSG, L"Error", MB_OK  );
					SetFocus( GetDlgItem( hDlg, IDC_IPEDIT ) );
					return FALSE;
				} else {
					 MessageBox( NULL, NO_PHONE_NUM_MSG, L"Error", MB_OK  );
					SetFocus( GetDlgItem( hDlg, IDC_IPEDIT ) );
					return FALSE;						
				}
			}
			
			// Add the buddy in RTC
			IRTCBuddy* pBuddy = NULL;
			pBuddy = AddBuddyRTC( szAddr, szName, bt, VARIANT_TRUE, m_hInstance);
			
			if (pBuddy)
				AddBuddyListView(esStat, pBuddy, szName, bt);
			
			EndDialog( hDlg, LOWORD( wParam ) );
			
			return TRUE;
			
		} // end if IDOK
		
		break;
	} // end switch
	return FALSE;
}


// Mesage handler for the Edit contact box
LRESULT CALLBACK Proc_EditBuddy(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	RECT rt1;
	IRTCBuddy* pBuddy = NULL;
	BSTR bstrName = NULL;
	BSTR bstrURI = NULL;

	
	switch (message)
	{
		case WM_INITDIALOG:
			if ( m_cSelectedBuddy.iSelectedBuddies != 1 )
			{
				return FALSE;
			}
			
			m_cSelectedBuddy.pBuddy->get_Name(&bstrName);

			if (m_cSelectedBuddy.btBuddyType == BT_PHONE) {
				m_cSelectedBuddy.pBuddy->get_Data(&bstrURI);
			} else {
				m_cSelectedBuddy.pBuddy->get_PresentityURI(&bstrURI);
			}

			SetDlgItemText( hDlg, IDC_NAMEEDIT, bstrName );
			SetDlgItemText( hDlg, IDC_IPEDIT, bstrURI );
			SendDlgItemMessage( hDlg, ( m_cSelectedBuddy.btBuddyType == BT_COMPUTER )?IDC_RADIO1:IDC_RADIO2, BM_SETCHECK, BST_CHECKED, 0 );
			
			SysFreeString( bstrName );
			SysFreeString( bstrURI );

			SendDlgItemMessage( hDlg, IDC_NAMEEDIT, EM_LIMITTEXT, MAINWND_BUDDYTXTLENGTH, 0 );
			SendDlgItemMessage( hDlg, IDC_IPEDIT, EM_LIMITTEXT, MAINWND_BUDDYTXTLENGTH, 0 );

			// trying to center the dialog
			if ( GetWindowRect( hDlg, &rt1 ) ) {
				CenterDialog(hDlg, rt1);
			}
			
			return TRUE;

		case WM_COMMAND:
			if ( (LOWORD( wParam ) == IDCANCEL ) )
			{
				EndDialog( hDlg, LOWORD( wParam ) );
				return TRUE;
			}

			TCHAR szName[ MAINWND_BUDDYTXTLENGTH + 4 ];
			TCHAR szAddr[ MAINWND_BUDDYTXTLENGTH + 4 ];

			if ( ( LOWORD( wParam ) == IDOK ) )
			{
		
				GetDlgItemText( hDlg, IDC_NAMEEDIT, szName, sizeof( szName )/sizeof( TCHAR ) );
				GetDlgItemText( hDlg, IDC_IPEDIT, szAddr, sizeof( szAddr )/sizeof( TCHAR ) );

				if ( *szName == '\0' )
				{
					MessageBox( NULL, L"You did not specify the contact's name.\r\n",
										   L"Error", MB_OK );
					return FALSE;
				}
								
				BUDDYTYPE enBt = BT_COMPUTER;
				if ( SendDlgItemMessage( hDlg, IDC_RADIO1, BM_GETCHECK, 0, 0 ) != BST_CHECKED )
					enBt = BT_PHONE;								
					
				if ( *szAddr == '\0') {
					if (enBt != BT_PHONE)	{					
						MessageBox( NULL, 
							L"You did not specify the contact's address.\r\n"
							L"Please use a proper SIP identifier:\r\n"
							L"IP address, Machine name, or email address, e.g.\r\n"
							L"1.2.3.4 -or- MyMachine -or- user@microsoft.com", L"Error", MB_OK  );
					} else {
						MessageBox( NULL, 
							L"You did not specify the contact's phone number.\r\n"
							L"e.g.: +1-555-555-1212", L"Error", MB_OK  );
					}
					SetFocus( GetDlgItem( hDlg, IDC_IPEDIT ) );
					return FALSE;
				}

				// Add then remove to ensure events transferred properly?
				// for now, assume they don't kill the URI
				EditBuddyRTC( m_cSelectedBuddy.pBuddy, szName, szAddr, enBt, m_hInstance );
				ESTATUS esStat = GetBuddyStatus( m_cSelectedBuddy.pBuddy, enBt );

				ChangeBuddyListView( m_cSelectedBuddy.pBuddy, szName, enBt, esStat );
				
				EndDialog( hDlg, LOWORD( wParam ) );
				
				return TRUE;
			}
	}
    return FALSE;
}


// Mesage handler for the Change My Status box
LRESULT CALLBACK Proc_MyStatus(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
	RECT rt1;

	switch (message)
	{
		case WM_INITDIALOG:
			// trying to center the dialog
			if ( GetWindowRect( hDlg, &rt1 ) )
			{
				CenterDialog(hDlg, rt1);
			}
			
			SendDlgItemMessage( hDlg, m_sProp.esMyStatus, BM_SETCHECK, BST_CHECKED, 0 );

			return TRUE;

		case WM_COMMAND:
			if ( (LOWORD( wParam ) == IDCANCEL ) )
			{
				EndDialog( hDlg, LOWORD( wParam ) );
				return TRUE;
			}

			if ( ( LOWORD( wParam ) == IDOK ) )
			{
				if ( SendDlgItemMessage( hDlg, ES_ONLINE, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_ONLINE;
				if ( SendDlgItemMessage( hDlg, ES_OFFLINE, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_OFFLINE;
				if ( SendDlgItemMessage( hDlg, ES_BUSY, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_BUSY;
				if ( SendDlgItemMessage( hDlg, ES_BEBACK, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_BEBACK;
				if ( SendDlgItemMessage( hDlg, ES_AWAY, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_AWAY;
				if ( SendDlgItemMessage( hDlg, ES_PHONE, BM_GETCHECK, 0, 0 ) == BST_CHECKED )
					m_sProp.esMyStatus = ES_PHONE;
				if ( SendDlgItemMessage( hDlg, ES_LUNCH, BM_GETCHECK, 0, 0 ) == BST_CHECKE

⌨️ 快捷键说明

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