📄 sessionwnd.cpp
字号:
return 1;
case SWCBM_IM_PARTICIPANT_REJECTED:
pSessionWindow->m_hIMSession = NULL;
pSessionWindow->ssMessage = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
pSessionWindow->SessionWndRedrawClient();
pSessionWindow->SessionWndScrollMessages();
// The caller should see a reject message
pSessionWindow->LocalMessage( LMT_PARTY_DECLINED, (BSTR) pMsgBody, L"messaging" );
return 1;
case SWCBM_IM_PARTICIPANT_LEFT:
{
if ( pSessionWindow )
{
// invalidate session handle
pSessionWindow->m_hIMSession = NULL;
pSessionWindow->ssMessage = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
pSessionWindow->SessionWndRedrawClient();
pSessionWindow->SessionWndScrollMessages();
// The caller should see a left message
pSessionWindow->LocalMessage( LMT_PARTY_LEFT, (BSTR) pMsgBody, L"messaging" );
}
// If it's waiting for accept, kill the msg box
TCHAR szTitle[ MAX_LOADSTRING ];
LoadString( m_hInstance, IDS_MSGSESSION, szTitle, MAX_LOADSTRING );
HWND hDlg = FindWindow( NULL, szTitle );
if ( hDlg )
SendMessage( hDlg, WM_COMMAND, IDIGNORE, 0 );
return 1;
}
case SWCBM_CALL_INITIATING_INCOMING:
case SWCBM_CALL_INITIATING_OUTGOING:
{
SWCB_PARTICIPANT_INFO* pPI = ( SWCB_PARTICIPANT_INFO* ) pMsgBody;
if ( eMsgType == SWCBM_CALL_INITIATING_INCOMING )
{
TCHAR* szTxt = ( TCHAR* ) malloc( ( wcslen( pPI->get_Name() ) + 64 ) * sizeof( TCHAR ) );
wsprintf( szTxt, L"%s is calling.\r\nDo you accept this voice session?", pPI->get_Name() );
TCHAR szTitle[ MAX_LOADSTRING ];
LoadString( m_hInstance, IDS_VOICESESSION, szTitle, MAX_LOADSTRING );
int iRet = MessageBox( NULL, szTxt, szTitle, MB_YESNO );
if (szTxt != NULL)
free( szTxt );
if ( iRet == IDNO )
{
// Return with rejected
return 0;
}
else
if ( iRet == IDABORT || iRet == IDIGNORE )
{
// Return with timed out
return 2;
}
}
// If there's no window (just receiving an invitation), pull up window now
if ( !pSessionWindow )
{
pSessionWindow = new CSessionWnd;
pSessionWindow->OpenSessionWnd( pPI, eMsgType );
} else {
pSessionWindow->cOtherParty.iSelectedBuddies++;
}
pSessionWindow->ssVoice = SS_INITIATING;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
if ( eMsgType == SWCBM_CALL_INITIATING_OUTGOING ) {
// create the call
pSessionWindow->m_hCallSession = OpenSessionTo( (PARTICIPANT_INFO*) pMsgBody,
(((PARTICIPANT_INFO*) pMsgBody)->btBuddyType == BT_COMPUTER) ? RTCST_PC_TO_PC : RTCST_PC_TO_PHONE, (FARPROC) SessionWndCallback);
if (!pSessionWindow->m_hCallSession) {
// Handle the failed session error
pSessionWindow->ssVoice = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
}
} else if ( eMsgType == SWCBM_CALL_INITIATING_INCOMING ) {
pSessionWindow->m_hCallSession = hSess;
DEBUGMSG( ZONE_STATUS, (L"Voipdemo:SessionWnd storing %l as the call session handle\r\n", hSess) );
}
return 1;
}
case SWCBM_P2P_CALL_INITIATING_OUTGOING:
{
// We will be passed an array of participant_info's dynamically allocated (we must destroy them)
// the Number of participants will be passed as hSess (number other than myself
int iNumParticipants = (int) hSess;
int i = 0;
ASSERT( iNumParticipants > 0);
ASSERT( pMsgBody != NULL);
PARTICIPANT_INFO*** pppPart = (PARTICIPANT_INFO***) pMsgBody;
BUDDY_SELECTION cBuddy;
cBuddy.put_Addr((*pppPart)[0]->get_Addr());
cBuddy.put_Name((*pppPart)[0]->get_Name());
cBuddy.iSelectedBuddies = iNumParticipants;
// If there's no window (just receiving an invitation), pull up window now
if ( !pSessionWindow )
{
pSessionWindow = new CSessionWnd;
pSessionWindow->OpenSessionWnd( (PARTICIPANT_INFO*) &cBuddy, eMsgType); // pass in buddy selection
}
pSessionWindow->ssVoice = SS_INITIATING;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
// create the call
pSessionWindow->m_hCallSession = OpenSessionTo( (PARTICIPANT_INFO*) &cBuddy,
RTCST_PHONE_TO_PHONE, (FARPROC) SessionWndCallback);
if (!pSessionWindow->m_hCallSession) {
// Handle the failed session error
pSessionWindow->ssVoice = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
} else {
// Add the remaining participants to the session
for (i = 1; i < iNumParticipants; i++) {
AddParticipantToSession( (*pppPart)[i], pSessionWindow->m_hCallSession, (FARPROC) SessionWndCallback);
}
}
// cleanup the array of callees that was passed in
for (i = 0; i < iNumParticipants; i++) {
delete (*pppPart)[i];
}
delete[] *pppPart;
*pppPart = NULL;
} // end SWCBM_P2P_CALL_INITIATING_OUTGOING
case SWCBM_CALL_PARTICIPANT_JOINED:
pSessionWindow->ssVoice = SS_GOING;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
// The caller should see an accept message
pSessionWindow->LocalMessage( LMT_PARTY_ACCEPTED, (BSTR) pMsgBody, L"voice" );
return 1;
case SWCBM_CALL_PARTICIPANT_REJECTED:
// register change with our count of the participants
pSessionWindow->cOtherParty.iSelectedBuddies--;
if ( pSessionWindow->cOtherParty.iSelectedBuddies < 1) {
pSessionWindow->m_hCallSession = NULL;
pSessionWindow->ssVoice = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
}
// The caller should see a reject message
pSessionWindow->LocalMessage( LMT_PARTY_DECLINED, (BSTR) pMsgBody, L"voice" );
return 1;
case SWCBM_CALL_PARTICIPANT_LEFT:
{
if ( pSessionWindow )
{
// register change with our count of the participants
pSessionWindow->cOtherParty.iSelectedBuddies--;
// invalidate the call session handle
if ( pSessionWindow->cOtherParty.iSelectedBuddies < 1) {
pSessionWindow->m_hCallSession = NULL;
pSessionWindow->ssVoice = SS_OFF;
pSessionWindow->InvalidateSessionButton( -100 );
pSessionWindow->SessionWndUpdateTitle();
// If it's waiting for accept, kill the msg box
TCHAR szTitle[ MAX_LOADSTRING ];
LoadString( m_hInstance, IDS_VOICESESSION, szTitle, MAX_LOADSTRING );
HWND hDlg = FindWindow( NULL, szTitle );
if ( hDlg )
SendMessage( hDlg, WM_COMMAND, IDIGNORE, 0 );
}
// The caller should see a left message
pSessionWindow->LocalMessage( LMT_PARTY_LEFT, (BSTR) pMsgBody, L"voice" );
}
return 1;
}
}
return 0;
}
/*************************************************************************************************
DestroySessionWindow
Call the session window's destructor.
*************************************************************************************************/
BOOL CSessionWndContainer::DestroySessionWindow( CSessionWnd* pSessionWnd )
{
if ( !pSessionWnd )
return FALSE;
delete pSessionWindow;
pSessionWindow = NULL;
return TRUE;
}
/*************************************************************************************************
CSessionWnd() constructor
Initialize internal variables and create the sessionwindow font.
*************************************************************************************************/
CSessionWnd::CSessionWnd()
{
m_hWndSession = 0;
m_hWndSessionCB = 0;
m_hMsgWindow = 0;
m_hEditWindow = 0;
m_hIMSession = NULL;
m_hCallSession = NULL;
m_bP2PSession = FALSE;
CSessionWnd::m_pEditProc = NULL;
m_nSessionButtonPointed = -1;
ssVoice = SS_OFF;
ssMessage = SS_OFF;
bToolbar = TRUE;
bStatusbar = TRUE;
bAlwaysOnTop = TRUE;
bTemporaryBuddy = FALSE;
wcscpy( szStatus, L"Ready" );
cOtherParty.iSelectedBuddies = 1;
cOtherParty.eStat = ES_OFFLINE;
bSetEditPos = FALSE;
bSetMsgPos = FALSE;
nMsgFontHight = 24;
nMsgLineLength = 40;
LOGFONT lFont;
memset( &lFont, 0, sizeof( lFont ) );
lFont.lfHeight = nMsgFontHight;
lFont.lfWeight = FW_BOLD;
lFont.lfCharSet = DEFAULT_CHARSET;
lFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
lFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
lFont.lfQuality = DEFAULT_QUALITY;
lFont.lfPitchAndFamily = DEFAULT_PITCH | FF_SWISS;
m_hFont = CreateFontIndirect( &lFont );
}
/*************************************************************************************************
~CSessionWnd destructor
Destroy the sesion window and delete the font created in the ctor.
*************************************************************************************************/
CSessionWnd::~CSessionWnd()
{
if ( m_hWndSession )
DestroyWindow( m_hWndSession );
DeleteObject( m_hFont );
}
/*************************************************************************************************
SessionWndUpdateTitle
Update the window title bar to show the state of the session (voice and/or im)
*************************************************************************************************/
void CSessionWnd::SessionWndUpdateTitle()
{
TCHAR szTitle[256];
wsprintf( szTitle, L" %s - %s%s%s Session",
( m_bP2PSession) ? L"Conference Call": cOtherParty.get_Name(),
( ssVoice != SS_OFF )? L"Voice":L"",
( ssMessage != SS_OFF && ssVoice != SS_OFF )? L" & ":L"",
( ssMessage != SS_OFF )? L"Messaging":L"" );
SetWindowText( m_hWndSession, szTitle );
wsprintf( szStatus, L"%s%s%s%s%s",
( ssVoice != SS_OFF )? L"Voice: ":L"",
( ssVoice == SS_INITIATING )? L"Initializing ":
( ssVoice == SS_GOING )? L"Online ":
( ssVoice == SS_QUITTING )? L"Terminating ":L"",
( ssMessage != SS_OFF && ssVoice != SS_OFF )? L" & ":
( ssMessage == SS_OFF && ssVoice == SS_OFF )? L"Ready":L"",
( ssMessage != SS_OFF )? L"Messaging: ":L"",
( ssMessage == SS_INITIATING )? L"Initializing":
( ssMessage == SS_GOING )? L"Online":
( ssMessage == SS_QUITTING )? L"Terminating":L"" );
if ( m_hWndSession && bStatusbar )
{
RECT rt;
GetClientRect( m_hWndSession, &rt );
RECT ri = { rt.left, rt.bottom - SESSIONWND_STATUSBARHEIGHT, rt.right, rt.bottom };
InvalidateRect( m_hWndSession, &ri, FALSE );
}
}
/*************************************************************************************************
*************************************************************************************************/
void CSessionWnd::SessionWndRedrawClient()
{
RECT rt, ri;
if ( m_hWndSession )
{
GetClientRect( m_hWndSession, &rt );
ri.top = rt.top + SESSIONWND_TOOLBARHEIGHT + GetSystemMetrics( SM_CYMENU ) + 4;
if ( !bToolbar )
ri.top = rt.top + 4 + GetSystemMetrics( SM_CYMENU ) + 2;
ri.bottom = rt.bottom;
if ( bStatusbar )
ri.bottom = rt.bottom - SESSIONWND_STATUSBARHEIGHT;
ri.left = rt.left;
ri.right = rt.right;
InvalidateRect( m_hWndSession, &ri, FALSE );
UpdateWindow( m_hWndSession );
}
}
/*************************************************************************************************
SessionWndScrollMessages
Scroll the messages in the listview ??
*************************************************************************************************/
void CSessionWnd::SessionWndScrollMessages()
{
if ( !m_hMsgWindow )
return;
int nIndex;
nIndex = SendMessage( m_hMsgWindow, LB_GETCURSEL, 0, 0 );
if ( nIndex == 0 || nIndex == LB_ERR )
{
nIndex = ListView_GetItemCount( m_hMsgWindow );
if ( nIndex > 0 )
nIndex--;
}
ListView_EnsureVisible( m_hMsgWindow, nIndex, FALSE );
}
/*************************************************************************************************
LocalMessage
Display a local status message of msgtype eType.
Note: this function will initiate a callback to the sessionwindowcallback function.
*************************************************************************************************/
void CSessionWnd::LocalMessage( LOCALMSGTYPE eType, TCHAR* szPartyName, TCHAR* szTxt )
{
if ( !m_hWndSession )
return;
TCHAR szMsg[ 512 ];
switch( eType )
{
default:
case LMT_TEXT:
wcscpy( szMsg, szTxt );
break;
case LMT_PARTY_STATUS_CHANGE:
wsprintf( szMsg, L"%s's status has changed to: %s", szPartyName, szTxt );
break;
case LMT_PARTY_ACCEPTED:
wsprintf( szMsg, L"%s has accepted the %s session", szPartyName, szTxt );
break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -