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

📄 sessionwnd.cpp

📁 Windows CE .Net 下面 VOIP编程的经典实例。对于初学Windows 平台下VOIP编程技术的程序员颇具借鉴意义!
💻 CPP
📖 第 1 页 / 共 4 页
字号:
			break;
			
		case WM_CREATE:
			break;
			
		case WM_PAINT:
			return pThis->DoSessionWndPaint( wParam, lParam );

		case WM_MOUSEMOVE:
			return pThis->DoSessionWndMouseMove( wParam, lParam );

		case WM_LBUTTONUP:
			nB = pThis->m_nSessionButtonPointed;
			
			// Deselect the buttons (m_nButtonPointed is invalid from now)
			pThis->DoSessionWndMouseMove( 0, 0 );
			
			switch( m_sSessionButtons[ nB ].r[ 0 ] )
			{
				 case IDB_SENDBTN:
				 	SendMessage( pThis->m_hWndSession, WM_COMMAND, ID_TOOLS_SENDINSTANTMESSAGE, 0 );
				 	break;

				 case IDB_CALLBTN:
				 	SendMessage( pThis->m_hWndSession, WM_COMMAND, ID_TOOLS_CALL, 0 );
				 	break;

				 case IDB_STATBTN:
				 	SendMessage( pThis->m_hWndSession, WM_COMMAND, ID_FILE_MYSTATUS, 0 );
				 	break;

				 case IDB_FONTBTN:
				 	SendMessage( pThis->m_hWndSession, WM_COMMAND, ID_EDIT_CHANGEFONT, 0 );
				 	break;

				 case IDB_SMSGBTN:
				 	SendMessage( pThis->m_hWndSession, WM_COMMAND, ID_EDIT_SENDMESSAGE, 0 );
				 	break;

			}

			return 0;
			
		case WM_DESTROY:

			// Stop messaging session
			if ( pThis->m_hIMSession && pThis->ssMessage != SS_QUITTING && pThis->ssMessage != SS_OFF) {
				SessionStop( pThis->m_hIMSession );
				pThis->m_hIMSession;
			}
				
			// Stop voice session
			if ( pThis->m_hIMSession && pThis->ssVoice != SS_QUITTING && pThis->ssVoice != SS_OFF) {
				SessionStop( pThis->m_hCallSession );
				pThis->m_hCallSession;
			}				

			CommandBar_Destroy( pThis->m_hWndSessionCB );
			DestroyWindow( pThis->m_hMsgWindow );
			DestroyWindow( pThis->m_hEditWindow );
			pThis->m_hWndSession = NULL;			// Session window
			pThis->m_hWndSessionCB = NULL;			// The command bar handle
			pThis->m_hMsgWindow = NULL;				// The message window
			pThis->m_hEditWindow = NULL;			// The edit window
			pThis->ssVoice = SS_OFF;
			pThis->ssMessage = SS_OFF;
			pThis->m_nSessionButtonPointed = -1;

#ifdef RTC_PERSISTENT_STORAGE_UNIMPLEMENTED
			// we're importing and exporting buddies on the fly, remove all temporary entries
			if (pThis->bTemporaryBuddy) {
				RemoveBuddyRTC(pThis->cOtherParty.pBuddy, pThis->cOtherParty.btBuddyType);
			}
#endif // RTC_PERSISTENT_STORAGE_UNIMPLEMENTED

			pThis->bTemporaryBuddy = FALSE;
			pThis->cOtherParty.Init();			
		
			CSessionWndContainer::DestroySessionWindow( pThis );

			break;

		case WM_INITMENUPOPUP:
			{
				HMENU hmenuPopup = ( HMENU )wParam;
				CheckMenuItem( hmenuPopup, ID_VIEW_TOOLBAR, MF_BYCOMMAND|( pThis->bToolbar )?MF_CHECKED:MF_UNCHECKED );
				CheckMenuItem( hmenuPopup, ID_VIEW_STATUSBAR, MF_BYCOMMAND|( pThis->bStatusbar )?MF_CHECKED:MF_UNCHECKED );
				CheckMenuItem( hmenuPopup, ID_VIEW_ALWAYSONTOP, MF_BYCOMMAND|( pThis->bAlwaysOnTop )?MF_CHECKED:MF_UNCHECKED );
				
				EnableMenuItem( hmenuPopup, ID_TOOLS_CALL,  MF_BYCOMMAND| (pThis->cOtherParty.CallCapable() && pThis->m_bP2PSession == FALSE) ?  MF_ENABLED : MF_GRAYED);
				EnableMenuItem( hmenuPopup, ID_TOOLS_SENDINSTANTMESSAGE,  MF_BYCOMMAND|(pThis->cOtherParty.IMCapable()) ?  MF_ENABLED : MF_GRAYED );

				break;
			}

		default:
			return DefWindowProc( hWnd, message, wParam, lParam );
   }

   return 0;
}

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

  DoSessionWndPaint

	Paint the sesion window.  Draws the window background, positions the listview, the editbox, 
	then the status bar, toolbar, and paints the buttons on the toolbar and edit window (if
	applicable).

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

LRESULT CSessionWnd::DoSessionWndPaint( WPARAM wParam, LPARAM lParam )
{
	RECT rt;
	PAINTSTRUCT ps;

	int nCurrentStatusHeight = 0;
	if ( bStatusbar )
		nCurrentStatusHeight = SESSIONWND_STATUSBARHEIGHT;

	int nCurrentClientArea = GetSystemMetrics( SM_CYMENU ) + 6;
	if ( bToolbar )
		nCurrentClientArea += SESSIONWND_TOOLBARHEIGHT;


	HDC hdc = BeginPaint( m_hWndSession, &ps );
	GetClientRect( m_hWndSession, &rt );

	HBRUSH hWhiteBrush = GetSysColorBrush( COLOR_WINDOW );
	HPEN hNullPen = CreatePen( PS_NULL, 0, 0 );
	
	HBRUSH hOldBrush = ( HBRUSH )SelectObject( hdc, hWhiteBrush );
	HPEN hOldPen = ( HPEN )SelectObject( hdc, hNullPen );

	// Draw the msg list area
	int nTop = rt.top + SESSIONWND_TOOLBARHEIGHT + GetSystemMetrics( SM_CYMENU ) + 4;
	if ( !bToolbar )
		nTop = rt.top + 4 + GetSystemMetrics( SM_CYMENU ) + 2;

	int nBottom = rt.bottom - 24 - SESSIONWND_EDITBOXHEIGHT - nCurrentStatusHeight;
	if ( ssMessage == SS_OFF || ssMessage == SS_INITIATING_INCOMING	)
		nBottom = rt.bottom - 4  - nCurrentStatusHeight;
	
	RoundRect( hdc, rt.left + 4, nTop,
		rt.right - 4, nBottom, 2*8, 2*8 );

	// Position the list window in the area (only once)
	if ( m_hMsgWindow ) //!bSetMsgPos &&
	{
		SetWindowPos( m_hMsgWindow, 0,
						rt.left + 12,
						nTop + 8,
						rt.right - 12 -rt.left - 12,
						nBottom - 16 - nTop,
						SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW );
		
		bSetMsgPos = TRUE;
		LV_COLUMN lvc;
		lvc.mask = LVCF_WIDTH;
		lvc.cx = rt.right - 12 -rt.left - 12 - 2 - GetSystemMetrics( SM_CXVSCROLL );
		ListView_SetColumn( m_hMsgWindow, 0, &lvc );
	}	


	// Draw the editbox area only if msg session is going on
	if ( ssMessage != SS_OFF && ssMessage != SS_INITIATING_INCOMING	)
	{
		RoundRect( hdc, rt.left + 4, rt.bottom - 20 - SESSIONWND_EDITBOXHEIGHT - nCurrentStatusHeight,
			rt.right - 4, rt.bottom - 4  - nCurrentStatusHeight, 2*8, 2*8 );

		// Calculate the position of the Send Message button
		HBITMAP hButton = LoadBitmap( CSessionWndContainer::hInstance, MAKEINTRESOURCE( m_sSessionButtons[ MSGSENDBUTTON ].r[ 0 ] ) );
		HDC hBmpDC = CreateCompatibleDC( hdc );
		HBITMAP hOldBmp = ( HBITMAP )SelectObject( hBmpDC, hButton );

		BITMAP sButton;
		memset( &sButton, 0, sizeof( BITMAP ) );
		GetObject( hButton, sizeof( BITMAP ), &sButton );

		m_sSessionButtons[ MSGSENDBUTTON ].x = rt.right - 12 - sButton.bmWidth - 8;
		m_sSessionButtons[ MSGSENDBUTTON ].y = rt.bottom - 4 - SESSIONWND_EDITBOXHEIGHT - nCurrentStatusHeight - GetSystemMetrics( SM_CYMENU );
		m_sSessionButtons[ MSGSENDBUTTON ].cx = sButton.bmWidth;
		m_sSessionButtons[ MSGSENDBUTTON ].cy = sButton.bmHeight;

		// Position the editbox in the area
		if ( m_hEditWindow )
		{
			SetWindowPos( m_hEditWindow, 0,
							rt.left + 12,
							rt.bottom - 12 - SESSIONWND_EDITBOXHEIGHT - nCurrentStatusHeight,
							m_sSessionButtons[ MSGSENDBUTTON ].x - rt.left - 20,
							SESSIONWND_EDITBOXHEIGHT,						
							SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW );
		}
		
		SelectObject( hBmpDC, hOldBmp );
		DeleteObject( hButton );
		DeleteDC( hBmpDC );
	}
	else
	{
		// If no msg session is on, hide the edit box
		ShowWindow( m_hEditWindow, SW_HIDE );
	}

	#define SEP_COL_STEPS	32

	// Draw the status bar (only if it's visible)
	if ( bStatusbar )
	{
		RECT ri = { rt.left+2, rt.bottom - nCurrentStatusHeight, rt.right-2, rt.bottom-2 };

		POINT p[3];
		p[0].x = ri.left;
		p[0].y = ri.bottom;
		p[1].x = ri.left;
		p[1].y = ri.top;
		p[2].x = ri.right;
		p[2].y = ri.top;

		HPEN hC = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DDKSHADOW ) );
		SelectObject( hdc, hC );
		Polyline( hdc, &p[0], 3 );
		SelectObject( hdc, hOldPen );
		DeleteObject( hC );

		p[0].x = ri.left;
		p[0].y = ri.bottom;
		p[1].x = ri.right;
		p[1].y = ri.bottom;
		p[2].x = ri.right;
		p[2].y = ri.top;

		hC = CreatePen( PS_SOLID, 1, GetSysColor( COLOR_3DLIGHT ) );
		SelectObject( hdc, hC );
		Polyline( hdc, &p[0], 3 );
		SelectObject( hdc, hOldPen );
		DeleteObject( hC );

		SetBkColor( hdc, GetSysColor( COLOR_3DFACE ) );
		SetTextColor( hdc, GetSysColor( COLOR_BTNTEXT ) );

		RECT rt = { ri.left+1, ri.top+1, ri.right-1, ri.bottom-1 };

		ExtTextOut( hdc, rt.left + 12, rt.top, ETO_CLIPPED|ETO_OPAQUE, &rt, szStatus, wcslen( szStatus ), 0 );
	}

	// Draw the parts of the toolbar (only if it's visible)
	if ( bToolbar )
	{
		// Clear the toolbar background
		SelectObject( hdc, hWhiteBrush );

		SelectObject( hdc, hNullPen );

		RoundRect( hdc, rt.left + 4, rt.top + 4 + GetSystemMetrics( SM_CYMENU ) + 2,
			rt.right - 4, SESSIONWND_TOOLBARHEIGHT + GetSystemMetrics( SM_CYMENU ), 2*8, 2*8 );

		SelectObject( hdc, hOldBrush );
	}


	// Now stick the buttons on the window
	for ( int c = 0; c < sizeof ( m_sSessionButtons ) / sizeof ( SBUTTONDATA ); c++ )
	{
		// Only if it's the send message button and we have messaging, or any other button and the toolbar is visible
		if ( ( c == MSGSENDBUTTON && ssMessage != SS_OFF ) || 
			 ( c != MSGSENDBUTTON && bToolbar ) )
		{
			HBITMAP hButton = 0;
			
			// Check off the Call or Send if call or IM session is not Off
			if ( ( m_sSessionButtons[ c ].r[ 0 ] == IDB_CALLBTN && ssVoice != SS_OFF ) ||
				 ( m_sSessionButtons[ c ].r[ 0 ] == IDB_SENDBTN && ssMessage != SS_OFF ) )
				hButton = LoadBitmap( CSessionWndContainer::hInstance, MAKEINTRESOURCE( m_sSessionButtons[ c ].r[ 1 ] ) );
			else
			// Disable the Call button if buddy is a computer not online,
			// or if it's the Send button and buddy is not a computer
			// or button Send Message if no text in the edit box or no messaging session 
			if ( ( m_sSessionButtons[ c ].r[ 0 ] == IDB_CALLBTN && (
					 !cOtherParty.CallCapable() || m_bP2PSession)) || // don't want to enable re-dialing on P2P calls
				 ( m_sSessionButtons[ c ].r[ 0 ] == IDB_SENDBTN && !cOtherParty.IMCapable() ) ||
				 ( m_sSessionButtons[ c ].r[ 0 ] == IDB_SMSGBTN && !GetWindowTextLength( m_hEditWindow ) ) ||
				 ( m_sSessionButtons[ c ].r[ 0 ] == IDB_SMSGBTN && ssMessage == SS_OFF ) )
				hButton = LoadBitmap( CSessionWndContainer::hInstance, MAKEINTRESOURCE( m_sSessionButtons[ c ].r[ 2 ] ) );
			else
			// Show the default button
				hButton = LoadBitmap( CSessionWndContainer::hInstance, MAKEINTRESOURCE( m_sSessionButtons[ c ].r[ 0 ] ) );

			HDC hBmpDC = CreateCompatibleDC( hdc );
			HBITMAP hOldBmp = ( HBITMAP )SelectObject( hBmpDC, hButton );

			BITMAP sButton;
			memset( &sButton, 0, sizeof( BITMAP ) );
			GetObject( hButton, sizeof( BITMAP ), &sButton );

			BitBlt( hdc, rt.left + m_sSessionButtons[ c ].x + m_sSessionButtons[ c ].cx/2 - sButton.bmWidth/2, rt.top + m_sSessionButtons[ c ].y + m_sSessionButtons[ c ].cy/2 - sButton.bmHeight/2 + GetSystemMetrics( SM_CYMENU ),
					sButton.bmWidth, sButton.bmHeight, hBmpDC, 0, 0, SRCCOPY );

			SelectObject( hBmpDC, hOldBmp );
			DeleteObject( hButton );
				
			DeleteDC( hBmpDC );
		}
	}

	DrawSessionWndButtons( hdc );

	SelectObject( hdc, hOldPen );
	SelectObject( hdc, hOldBrush );

	DeleteObject( hNullPen );

	EndPaint( m_hWndSession, &ps );

	return 0;
}

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

  DoSessionWndMouseMove

	Move the mouse and check if it runs into the toolbar button (to show selected or de-selected)

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

LRESULT CSessionWnd::DoSessionWndMouseMove( WPARAM wParam, LPARAM lParam )
{
	int xPos = LOWORD( lParam );
	int yPos = HIWORD( lParam );

	int onButtonPointed = m_nSessionButtonPointed;
	m_nSessionButtonPointed = -1;

	// Check for hitting the toolbar buttons
	for ( int c = 0; c < sizeof ( m_sSessionButtons ) / sizeof ( SBUTTONDATA ); c++ )
	{
		// Only if toolbar is visible or this is the send message button
		if ( bToolbar || c == MSGSENDBUTTON )
		{
			if ( m_sSessionButtons[ c ].x && m_sSessionButtons[ c ].y &&
				 xPos >= m_sSessionButtons[ c ].x && xPos < m_sSessionButtons[ c ].x + m_sSessionButtons[ c ].cx &&
				 yPos >= GetSystemMetrics( SM_CYMENU ) + m_sSessionButtons[ c ].y && yPos < GetSystemMetrics( SM_CYMENU ) + m_sSessionButtons[ c ].y + m_sSessionButtons[ c ].cy )
			{
				m_nSessionButtonPointed = c;
				break;
			}
		}
	}


	// If the selected button has changed, revalidate the old and new selected buttons
	if ( m_nSessionButtonPointed != onButtonPointed )
	{
		InvalidateSessionButton( onButtonPointed );
		InvalidateSessionButton( m_nSessionButtonPointed );
}

	return 0;
}

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

  DrawSessionWndButtons

	Paint the sessionwindow button that the cursor is over

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

void CSessionWnd::DrawSessionWndButtons( HDC hdc )
{
	if ( m_nSessionButtonPointed > -1 )
	{
		POINT p[3];
		p[0].x = m_sSessionButtons[ m_nSessionButtonPointed ].x;
		p[0].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + m_sSessionButtons[ m_nSessionButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
		p[1].x = m_sSessionButtons[ m_nSessionButtonPointed ].x;
		p[1].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + GetSystemMetrics( SM_CYMENU );
		p[2].x = m_sSessionButtons[ m_nSessionButtonPointed ].x + m_sSessionButtons[ m_nSessionButtonPointed ].cx;
		p[2].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + GetSystemMetrics( SM_CYMENU );

		HPEN hC = CreatePen( PS_SOLID, 2, RGB( 64, 196, 255 ) );
		HPEN hOC = ( HPEN )SelectObject( hdc, hC );
		Polyline( hdc, &p[0], 3 );

		p[0].x = m_sSessionButtons[ m_nSessionButtonPointed ].x;
		p[0].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + m_sSessionButtons[ m_nSessionButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
		p[1].x = m_sSessionButtons[ m_nSessionButtonPointed ].x + m_sSessionButtons[ m_nSessionButtonPointed ].cx;
		p[1].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + m_sSessionButtons[ m_nSessionButtonPointed ].cy + GetSystemMetrics( SM_CYMENU );
		p[2].x = m_sSessionButtons[ m_nSessionButtonPointed ].x + m_sSessionButtons[ m_nSessionButtonPointed ].cx;
		p[2].y = m_sSessionButtons[ m_nSessionButtonPointed ].y + GetSystemMetrics( SM_CYMENU );

		SelectObject( hdc, hOC );
		DeleteObject( hC );

		hC = CreatePen( PS_SOLID, 2, RGB( 0, 64, 196 ) );
		SelectObject( hdc, hC );
		Polyline( hdc, &p[0], 3 );

		SelectObject( hdc, hOC );
		DeleteObject( hC );
	}
}

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

  InvalidateSessionButton
	
	Invalidate the selected button to be repainted by DrawSessionWndButtons

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

void CSessionWnd::InvalidateSessionButton( int nButton )
{
	if ( nButton != -100 && nButton < 0 )
		return;

	for ( int c = 0; c < sizeof ( m_sSessionButtons ) / sizeof ( SBUTTONDATA ) || nButton != -100; c++ )
	{
		if ( nButton != -100 )
			c = nButton;

		RECT cr;
		cr.top = m_sSessionButtons[ c ].y + GetSystemMetrics( SM_CYMENU ) - 1;
		cr.left = m_sSessionButtons[ c ].x - 1;
		cr.bottom = cr.top + m_sSessionButtons[ c ].cy + 2;
		cr.right = cr.left + m_sSessionButtons[ c ].cx + 2;
		InvalidateRect( m_hWndSession, &cr, FALSE );

		if ( nButton != -100 )
			break;
	}

}



⌨️ 快捷键说明

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