MainFrame.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:34k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // MainFrame.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Conference.h"
- #include "MainFrame.h"
- #include "CreateConferenceDlg.h"
- #include "LoginDlg.h"
- #include "ShowBroadcastDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CConferenceApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame
- CMainFrame::CMainFrame( ) : btmdlg( this )
- {
- this->m_view = new CMainView( );
- this->canTip = false;
- if( ! this->Create( NULL , "视频会议系统 - 用户名: " + ( CString )theApp.GetClient( ).GetUserName( ) + " 会议名: 时间: " , WS_OVERLAPPED | WS_SYSMENU | WS_MINIMIZEBOX | WS_VISIBLE , CRect( 0 , 0 , ::GetSystemMetrics( SM_CXSCREEN ) , ::GetSystemMetrics( SM_CYSCREEN ) ) , NULL , 0 ) )
- {
- delete this->m_view ; this->m_view = NULL;
- }
- }
- CMainFrame::~CMainFrame( )
- {
- }
- BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
- //{{AFX_MSG_MAP(CMainFrame)
- ON_WM_CREATE()
- ON_BN_CLICKED(IDC_CREATE_CONFERENCE_BUTTON, OnCreateConferenceButton)
- ON_BN_CLICKED(IDC_JOIN_CONFERENCE_BUTTON, OnJoinConferenceButton)
- ON_COMMAND(ID_WND_CONFERENCE_LIST, OnWndConferenceList)
- ON_COMMAND(ID_WND_CONFERENCE_ROOM, OnWndConferenceRoom)
- ON_WM_SHOWWINDOW()
- ON_WM_NCHITTEST()
- ON_WM_SYSCOMMAND()
- ON_WM_DESTROY()
- ON_WM_TIMER()
- ON_WM_CLOSE()
- //}}AFX_MSG_MAP
- ON_MESSAGE( CClient::MSG , OnPackageMessage )
- ON_COMMAND_RANGE( ID_CONFERENCE_CREATE , ID_CONFERENCE_EXIT , OnConference )
- ON_COMMAND_RANGE( ID_WND_1_VIDEO , ID_WND_1_VIDEO + VIDEO_WND_NUMBER , OnVideoWnd )
- ON_MESSAGE( WM_TRACER_MESSAGE , OnTrace )
- ON_MESSAGE( WM_ADD_USER , OnAddUser )
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMainFrame message handlers
- int CMainFrame::OnCreate( LPCREATESTRUCT lpCreateStruct )
- {
- if ( CFrameWnd::OnCreate( lpCreateStruct ) == -1 )
- return -1;
- //增加底部窗口
- this->btmdlg.Create( CBottomDialog::IDD );
- this->myBar.Create( this , RBS_AUTOSIZE , WS_CHILD | WS_VISIBLE | CBRS_BOTTOM );
- this->myBar.AddBar( &this->btmdlg , RGB( 214 , 239 , 255 ) , RGB( 214 , 239 , 255 ) , NULL , RBBS_NOGRIPPER );
- /*
- //设定菜单
- CMenu menu;
- menu.LoadMenu( IDR_MAIN_MENU );
- this->SetMenu( &menu );
- menu.Detach( );
- */
- //删除系统菜单的移动项
- this->GetSystemMenu( FALSE )->RemoveMenu( 1 , MF_BYPOSITION );
- //创建视图
- if( ! this->m_view->Create( NULL , NULL , AFX_WS_DEFAULT_VIEW , CRect( 0 , 0 , 0 , 0 ) , this , AFX_IDW_PANE_FIRST , NULL ) )
- return -1;
- //框架允许停靠在左边或者右边
- this->EnableDocking( CBRS_ALIGN_LEFT | CBRS_ALIGN_RIGHT );
- //创建会议列表窗口停靠栏
- if( this->sizeDlgBar.Create( "会议列表" , this , CSize( ::GetSystemMetrics( SM_CXSCREEN ) / 4 , ::GetSystemMetrics( SM_CYSCREEN ) * 3 / 4 ) , FALSE , 1 , WS_CHILD | WS_VISIBLE | CBRS_LEFT ) )
- {
- this->sizeDlgBar.SetSCBStyle( SCBS_SIZECHILD );
- this->sizeDlgBar.SetBarStyle( this->sizeDlgBar.GetBarStyle( ) | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- this->sizeDlgBar.EnableDocking( CBRS_ALIGN_LEFT );
- this->dlgBar.Create( CConferenceDialog::IDD , &this->sizeDlgBar );
- this->dlgBar.mainFrame = this;
- this->DockControlBar( &this->sizeDlgBar , AFX_IDW_DOCKBAR_LEFT );
- }//停靠的矩形窗口
- CRect rc;
- //创建5个视频窗口
- for( int i = 0; i < VIDEO_WND_NUMBER ; i ++ )
- {
- this->videoBar[ i ].Create( "视频窗口" , this , CSize( ::GetSystemMetrics( SM_CXSCREEN ) / 4 , ::GetSystemMetrics( SM_CYSCREEN ) / 4 ) , FALSE , 2 + i , WS_CHILD | WS_VISIBLE | ( ! i ? CBRS_LEFT : CBRS_RIGHT ) );
- this->videoBar[ i ].SetSCBStyle( SCBS_SIZECHILD );
- this->videoBar[ i ].SetBarStyle( this->videoBar[ i ].GetBarStyle( ) | CBRS_TOOLTIPS | CBRS_FLYBY | CBRS_SIZE_DYNAMIC );
- this->videoDlg[ i ].Create( CVideoDialog::IDD , &this->videoBar[ i ] );
- //第一个视频窗口
- if( i == 0 )
- {
- this->RecalcLayout( );
- this->dlgBar.GetWindowRect( &rc );
- rc.OffsetRect( 0 , 1 );
- this->videoBar[ i ].EnableDocking( CBRS_ALIGN_LEFT );
- this->DockControlBar( &this->videoBar[ i ] , AFX_IDW_DOCKBAR_LEFT , &rc );
- }//第二个视频窗口
- else if( i == 1 )
- {
- this->videoBar[ i ].EnableDocking( CBRS_ALIGN_RIGHT );
- this->DockControlBar( &this->videoBar[ i ] , AFX_IDW_DOCKBAR_RIGHT );
- }
- else //其他的视频窗口
- {
- this->RecalcLayout( );
- this->videoBar[ i - 1 ].GetWindowRect( &rc );
- rc.OffsetRect( 0 , 1 );
- this->videoBar[ i ].EnableDocking( CBRS_ALIGN_RIGHT );
- this->DockControlBar( &this->videoBar[ i ] , AFX_IDW_DOCKBAR_RIGHT , &rc );
- }
- }//载入窗口的排列状态
- CSizingControlBar::GlobalLoadState( this , "video_window" );
- //初始化窗口
- theApp.GetClient( ).InitVideo( this->videoDlg[ 0 ].GetSafeHwnd( ) );
- //预览
- theApp.GetClient( ).GetVideo( ).StartPreview( );
- //标记本地视频窗口
- if( theApp.GetClient( ).GetVideo( ) )
- {
- this->videoDlg[ 0 ].SetWindowText( "本地视频" );
- //通过设置窗口的属性保存该用户的id
- ::SetWindowLong( this->videoDlg[ 0 ].GetSafeHwnd( ) , GWL_USERDATA , true );
- }//消息处理句柄
- theApp.GetClient( ).AttachMsgHandler( this->GetSafeHwnd( ) );
- //请求在线用户状态
- theApp.GetClient( ).SendOnlineUserREQ( );
- //启动定时器为2分钟
- // this->SetTimer( 1 , 120000 , NULL );
- return 0;
- }
- //创建会议
- void CMainFrame::OnCreateConferenceButton( )
- {
- switch( this->dlgBar.m_tab.GetCurSel( ) )
- {
- case 0 : //邀请用户
- { //没有加入会议
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- MessageBox( "你还没有创建会议,不可以邀请用户" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }//不是主持人
- if( ! theApp.GetClient( ).IsCharement( ) )
- {
- MessageBox( "你不是主持人,不可以邀请用户加入你的会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- POSITION pos = this->dlgBar.m_olist.GetFirstSelectedItemPosition( ) ;
- if( pos == NULL )
- {
- MessageBox( "请在在线用户列表中选择你要邀请的用户" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- int nItem = 0 , user_id;
- CString status , name;
- //循环邀请用户加入会议
- while( pos )
- {
- nItem = this->dlgBar.m_olist.GetNextSelectedItem( pos );
- status = this->dlgBar.m_olist.GetItemText( nItem , 1 );
- if( status.Find( "空闲" ) == -1 )
- {
- if( this->dlgBar.m_olist.GetItemData( nItem ) != theApp.GetClient( ).GetUserID( ) )
- name += this->dlgBar.m_olist.GetItemText( nItem , 0 ) + "、";
- }
- else //发送邀请用户
- {
- user_id = this->dlgBar.m_olist.GetItemData( nItem );
- //强制邀请用户加入会议.
- theApp.GetClient( ).SendInviteUserREQ( user_id , false );
- //邀请加入会议,没有提示信息
- this->canTip = false;
- this->SetTimer( 3 , 60000 , NULL );
- }
- }//提示没有邀请到用户的原因
- if( ! name.IsEmpty( ) )
- MessageBox( "无法邀请 " + name + "因为他们在开会中" , "视频会议" , MB_ICONINFORMATION | MB_OK );
- }
- break;
- case 1 : //创建会议
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- if( theApp.GetClient( ).IsBroadcast( ) )
- {
- MessageBox( "你目前在处于广播状态,无法创建会议nn要创建会议,请退出广播" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- CCreateConferenceDlg dlg;
- if( dlg.DoModal( ) == IDOK )
- theApp.GetClient( ).SendCreateDataNode( dlg.m_name );
- }
- else
- MessageBox( "你已经在会议中,无法再次创建会议" , "视频会议客户端" , MB_ICONSTOP | MB_OK );
- break;
- case 2 : //退出会议
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- MessageBox( "你没有加入任何会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- //发送退出会议
- else if( MessageBox( "你确定要退出会议吗?" , "视频会议" ,MB_ICONQUESTION |MB_OKCANCEL ) == IDOK )
- {
- theApp.GetClient( ).SendExitDataNode( );
- //退出会议,会议室清空
- this->dlgBar.m_rlist.DeleteAllItems( );
- //图像清空
- for( int i = theApp.GetClient( ).GetVideo( ) ? 1 : 0 ; i < VIDEO_WND_NUMBER; i ++ )
- {
- this->videoDlg[ i ].SetWindowText( "" );
- ::SetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ), GWL_USERDATA , 0 );
- this->videoDlg[ i ].Invalidate( );
- }
- }
- break;
- }
- }
- //加入会议
- void CMainFrame::OnJoinConferenceButton( )
- { //上课
- if( this->dlgBar.m_tab.GetCurSel( ) == 0 )
- {
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- MessageBox( "你还没有创建会议,不可以邀请用户" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- if( ! theApp.GetClient( ).IsCharement( ) )
- {
- MessageBox( "你不是主持人,不可以邀请用户加入你的会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- POSITION pos = this->dlgBar.m_olist.GetFirstSelectedItemPosition( ) ;
- if( pos == NULL )
- {
- MessageBox( "请在在线用户列表中选择你要邀请的用户" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- int nItem = 0 , user_id;
- CString status , name;
- while( pos )
- {
- nItem = this->dlgBar.m_olist.GetNextSelectedItem( pos );
- status = this->dlgBar.m_olist.GetItemText( nItem , 1 );
- if( status.Find( "空闲" ) == -1 )
- name += this->dlgBar.m_olist.GetItemText( nItem , 0 ) + "、";
- else //发送邀请用户
- {
- user_id = this->dlgBar.m_olist.GetItemData( nItem );
- theApp.GetClient( ).SendInviteUserREQ( user_id , false );
- }
- }
- if( ! name.IsEmpty( ) )
- MessageBox( "无法邀请 " + name + "因为他们在开会中" , "视频会议" , MB_ICONINFORMATION | MB_OK );
- }//加入会议
- if( this->dlgBar.m_tab.GetCurSel( ) == 1 )
- {
- POSITION pos = this->dlgBar.m_clist.GetFirstSelectedItemPosition( );
- if( pos )
- {
- if( ! theApp.GetClient( ).GetConferenceName( ).empty( ) )
- MessageBox( "你已经在会议中,无法再次加入会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- else
- {
- int index = this->dlgBar.m_clist.GetNextSelectedItem( pos );
- theApp.GetClient( ).SendJoinDataNodeREQ( this->dlgBar.m_clist.GetItemText( index , 0 ) );
- //等待主持人回复
- CInitDialog dlg( "等待主持人的回复,请等待..." );
- //用户点击取消按钮,取消等待加入会议
- if( dlg.DoModal( ) != IDOK )
- theApp.GetClient( ).GetConferenceName( ) = "";
- }
- }
- else
- MessageBox( "请在会议列表中选择一个会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- }//请求发言 或者 停止发言 或者 点名发言
- else if( this->dlgBar.m_tab.GetCurSel( ) == 2 )
- {
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- MessageBox( "你没有加入任何会议" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- CString name;
- this->dlgBar.m_btn2.GetWindowText( name );
- //如果是主持人
- if( theApp.GetClient( ).IsCharement( ) )
- {
- POSITION pos = this->dlgBar.m_rlist.GetFirstSelectedItemPosition( );
- if( pos )
- { //取出用户id
- int user_id = this->dlgBar.m_rlist.GetItemData( this->dlgBar.m_rlist.GetNextSelectedItem( pos ) );
- //点中自己的节点
- if( user_id == theApp.GetClient( ).GetUserID( ) )
- {
- MessageBox( "你是主持人,不可以停止发言" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }//点名发言
- if( name.Find( "点名发言" ) != -1 )
- { //判断窗口号是否可用
- for( int i = 0; i < VIDEO_WND_NUMBER; i ++ )
- if( ! ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA ) )
- break;
- if( i>= VIDEO_WND_NUMBER )
- MessageBox( "没有空闲的视频窗口显示发言人图像,请停止其他人的发言再试一试" , "视频会议" , MB_ICONSTOP | MB_OK );
- else
- theApp.GetClient( ).SendRecvAudioREQ( user_id );
- }//停止发言
- else if( name.Find( "停止发言" ) != -1 && MessageBox( "你确定要停止该用户的发言吗" , "视频会议" , MB_ICONQUESTION | MB_OKCANCEL ) == IDOK )
- theApp.GetClient( ).SendStopAudioREQ( user_id );
- }
- else
- MessageBox( "请选择你要" + name + "的用户" , "视频会议" , MB_ICONSTOP | MB_OK );
- }
- else
- { //申请发言
- if( name.Find( "申请发言" ) != -1 )
- {
- if( theApp.GetClient( ).GetSoundIn( ).IsRecording( ) )
- MessageBox( "你目前已经可以发言了" , "视频会议" , MB_ICONSTOP | MB_OK );
- else
- { //先判断视频窗口是否够用
- for( int i = 0 ; i < VIDEO_WND_NUMBER ; i ++ )
- if( ! ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA ) )
- break;
- if( i >= VIDEO_WND_NUMBER )
- MessageBox( "会议中有某个成员的视频窗口不够显示您的视频图像,无法请求发言" , "视频会议" , MB_ICONSTOP | MB_OK );
- else
- {
- theApp.GetClient( ).SendSendAudioREQ( );
- //等待主持人回复
- CInitDialog dlg( "等待主持人的回复,请等待..." );
- dlg.DoModal( );
- }
- }
- }//停止发言
- else if( name.Find( "停止发言" ) != -1 )
- {
- if( ! theApp.GetClient( ).GetSoundIn( ).IsRecording( ) )
- {
- MessageBox( "你目前没有发言" , "视频会议" , MB_ICONSTOP | MB_OK );
- return;
- }
- else if( MessageBox( "你确定要停止发言吗" , "视频会议" , MB_ICONQUESTION | MB_OKCANCEL ) == IDOK )
- theApp.GetClient( ).SendStopAudioREQ( );
- }
- }
- }
- }
- //取得主持人视频
- CWnd * CMainFrame::GetCharentWnd( void )
- {
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- CTipDialog::ShowTip( "你没有加入任何会议,没有主持人视频" );
- return NULL;
- }
- else
- { //返回主持人窗口
- if( theApp.GetClient( ).IsCharement( ) )
- {
- if( theApp.GetClient( ).GetVideo( ) )
- return &this->videoDlg[ 0 ];
- CTipDialog::ShowTip( "主持人没有视频" );
- //主持人没有图像
- return NULL;
- }//查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_STRING;
- info.psz = theApp.GetClient( ).GetConferenceName( ).c_str( );
- int id = 0;
- //提示
- if( ( id = this->dlgBar.m_clist.FindItem( &info ) ) < 0 )
- {
- CTipDialog::ShowTip( "你没有加入任何会议,没有主持人视频" );
- return NULL;
- }
- id = this->dlgBar.m_clist.GetItemData( id );
- for( int i = 0; i < VIDEO_WND_NUMBER ; i ++ )
- if( ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == id )
- return &this->videoDlg[ i ];
- //提示
- CTipDialog::ShowTip( "主持人没有视频" );
- return NULL;
- }
- }
- //取得本地图像
- CWnd * CMainFrame::GetLocalVideo( void )
- {
- return theApp.GetClient( ).GetVideo( ) ? &theApp.GetClient( ).GetVideo( ) : NULL;
- }
- //会议菜单响应函数
- void CMainFrame::OnConference( UINT nID )
- {
- switch( nID )
- { //创建会议
- case ID_CONFERENCE_CREATE :
- this->dlgBar.m_tab.SetCurSel( 1 );
- this->OnCreateConferenceButton( );
- break;
- //加入会议
- case ID_CONFERENCE_JOIN :
- this->dlgBar.m_tab.SetCurSel( 1 );
- this->OnJoinConferenceButton( );
- break;
- //退出会议
- case ID_CONFERENCE_EXIT :
- this->dlgBar.m_tab.SetCurSel( 2 );
- this->OnCreateConferenceButton( );
- break;
- }
- }
- //显示会议列表窗口
- void CMainFrame::OnWndConferenceList( )
- {
- this->ShowControlBar( &this->sizeDlgBar , true , false );
- this->dlgBar.m_tab.SetCurSel( 1 );
- }
- //显示会议室窗口
- void CMainFrame::OnWndConferenceRoom( )
- {
- this->ShowControlBar( &this->sizeDlgBar , true , false );
- this->dlgBar.m_tab.SetCurSel( 2 );
- }
- //视频数据窗口
- void CMainFrame::OnVideoWnd( UINT nID )
- {
- this->ShowControlBar( &this->videoBar[ nID - ID_WND_1_VIDEO ] , true , false );
- }
- //窗口刚要显示时
- void CMainFrame::OnShowWindow(BOOL bShow, UINT nStatus)
- {
- CFrameWnd::OnShowWindow(bShow, nStatus);
- //关闭初始化的窗口
- if( bShow && theApp.initdlg.GetSafeHwnd( ) )
- theApp.initdlg.SendMessage( WM_CLOSE );
- }
- //窗口不可以移动
- UINT CMainFrame::OnNcHitTest(CPoint point)
- {
- UINT hitTest = CFrameWnd::OnNcHitTest( point );
- return hitTest == HTCAPTION ? HTCLIENT : hitTest;
- }
- //数据包的解析
- int CMainFrame::OnPackageMessage( WPARAM wParam , LPARAM lParam )
- {
- CDataPackage * package = ( CDataPackage * )wParam;
- if( ! package )
- { //设置提示信息为无效
- this->canTip = false;
- //清除列表
- this->dlgBar.m_olist.DeleteAllItems( );
- this->dlgBar.m_clist.DeleteAllItems( );
- this->dlgBar.m_rlist.DeleteAllItems( );
- //清除窗口
- for( int i = theApp.GetClient( ).GetVideo( ) ? 1 : 0 ; i < VIDEO_WND_NUMBER; i ++ )
- {
- this->videoDlg[ i ].SetWindowText( "" );
- ::SetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->videoDlg[ i ].Invalidate( );
- }//自动连接服务器
- CLoginDlg dlg( true );
- if( dlg.DoModal( ) != IDOK )
- this->PostMessage( WM_CLOSE );
- else
- { //发送视频头信息
- theApp.GetClient( ).SendVideoHeader( );
- //请求在线用户状态
- theApp.GetClient( ).SendOnlineUserREQ( );
- }
- return 0;
- }
- switch( package->Tag )
- {//在线用户状态,包括登录、离线、创建会议、加入会议、退出会议
- case POnlineUserRESTAG : this->OnlineUser( package ); break;
- //加入会议请求
- case PJoinDataNodeREQTAG : return this->OnJoinDataNodeREQ( package );
- //加入会议回复
- case PJoinDataNodeRESTAG : return this->OnJoinDataNodeRES( package );
- //邀请用户请求
- case PInviteUserREQTAG : return ( int )this->OnInviteUserREQ( package );
- //邀请用户回复
- case PInviteUserRESTAG : this->OnInviteUserRES( package ); break;
- //申请发言
- case PSendAudioRESTAG : return this->OnSendAudioRES( package );
- //视频信息
- case PVideoDataTAG : return this->OnVideoData( package );
- //发送音频请求
- case PSendAudioREQTAG : return this->OnSendAudioREQ( package );
- //主持人点名发言
- case PRecvAudioREQTAG : CTipDialog::ShowTip( "主持人点名了你发言,你可以发言了" ); break;
- //主持人点名发言回复
- case PRecvAudioRESTAG :
- {
- PRecvAudioRES * res = ( PRecvAudioRES * )package;
- if( ! res->success )
- { //查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = res->user_id;
- int index = this->dlgBar.m_rlist.FindItem( &info );
- if( index >= 0 )
- CTipDialog::ShowTip( "点名" + this->dlgBar.m_rlist.GetItemText( index , 0 ) + " 发言失败n可能对方没有声卡" );
- }
- }break;
- //模块信息
- case PModulePackageTAG :
- {
- PModulePackage * m = ( PModulePackage * )package;
- this->GetView( )->SetModulePackage( m->module , m->module_buffer , m->module_size );
- }
- break;
- //会议同步命令包
- case PSynCommandTAG :
- this->btmdlg.PostMessage( WM_FULLWND , ( ( PSynCommand * )package )->syncommand , ( ( PSynCommand * )package )->full_screen );
- break;
- //广播信息
- case PBroadcastREQTAG :
- {
- PBroadcastREQ * req = ( PBroadcastREQ * )package;
- //查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = req->broadcast_user_id;
- int index = this->dlgBar.m_olist.FindItem( &info );
- if( index >= 0 )
- {
- HWND hWnd = NULL;
- if( req->header && req->header_size )
- { //创建视频广播窗口
- CShowBroadcastDialog * dlg = new CShowBroadcastDialog( );
- dlg->Create( this );
- hWnd = dlg->GetSafeHwnd( );
- dlg->SetWindowText( "广播者: " + this->dlgBar.m_olist.GetItemText( index , 0 ) + " (按 Esc 退出广播)");
- }//提示
- CTipDialog::ShowTip( "用户 " + this->dlgBar.m_olist.GetItemText( index , 0 ) + " 给你发送广播消息" );
- return ( int )hWnd;
- }
- return NULL;
- }
- break;
- //广播回复
- case PBroadcastRESTAG :
- //如果目前还在广播中
- if( theApp.GetClient( ).IsBroadcast( ) )
- {
- PBroadcastRES * res = ( PBroadcastRES * )package;
- //查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = res->user_id;
- int index = this->dlgBar.m_olist.FindItem( &info );
- //提示
- if( index >= 0 )
- CTipDialog::ShowTip( "发送广播给用户 " + this->dlgBar.m_olist.GetItemText( index , 0 ) + ( res->success ? " 成功" : " 失败可能原因是n1、对方已经在别的广播中n2、对方关闭了你的广播" ) );
- }
- break;
- }
- return 0;
- }
- //在线用户状态
- void CMainFrame::OnlineUser( void * package )
- {
- POnlineUserRES * res = ( POnlineUserRES * )package;
- if( ! this->dlgBar.GetSafeHwnd( ) ) return;
- //查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = res->user_id;
- int index = -1;
- //用户名为空,表示该用户退出系统
- if( res->user_name.empty( ) )
- { //在线用户
- if( ( index = this->dlgBar.m_olist.FindItem( &info ) ) >= 0 )
- { //提示退出系统
- CTipDialog::ShowTip( "用户 " + this->dlgBar.m_olist.GetItemText( index , 0 ) + " 下线了" );
- this->dlgBar.m_olist.DeleteItem( index );
- }//会议列表
- if( ( index = this->dlgBar.m_clist.FindItem( &info ) ) >= 0 )
- this->dlgBar.m_clist.DeleteItem( index );
- //会议室列表
- if( ( index = this->dlgBar.m_rlist.FindItem( &info ) ) >= 0 )
- this->dlgBar.m_rlist.DeleteItem( index );
- }//用户名不空,表明在线
- else
- { //在线用户列表
- if( ( index = this->dlgBar.m_olist.FindItem( &info ) ) < 0 )
- { //用户上线
- if( res->user_id != theApp.GetClient( ).GetUserID( ) && this->canTip )
- //提示上线
- CTipDialog::ShowTip( "用户 " + ( CString )res->user_name.c_str( ) + " 上线了" );
- //增加该用户
- index = this->dlgBar.m_olist.InsertItem( 0 , res->user_name.c_str( ) );
- //用户id
- this->dlgBar.m_olist.SetItemData( index , res->user_id );
- }//用户状态
- this->dlgBar.m_olist.SetItemText( index , 1 , res->data_name.empty( ) ? "空闲" : "开会" );
- //如果会议名为空
- if( res->data_name.empty( ) )
- { //会议列表,退出会议
- if( res->isCharement && ( index = this->dlgBar.m_clist.FindItem( &info ) ) >= 0 )
- { //如果是主持人退出了会议,那么发送退出会议命令包
- if( ! theApp.GetClient( ).GetConferenceName( ).empty( ) && this->dlgBar.m_clist.GetItemText( index , 0 ) == theApp.GetClient( ).GetConferenceName( ).c_str( ) )
- { //发送退出会议
- theApp.GetClient( ).SendExitDataNode( );
- //清除所有会议成员
- this->dlgBar.m_rlist.DeleteAllItems( );
- //还原窗口状态
- for( int i = theApp.GetClient( ).GetVideo( ) ? 1 : 0 ; i < VIDEO_WND_NUMBER ; i ++ )
- {
- ::SetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->videoDlg[ i ].SetWindowText( "" );
- this->videoDlg[ i ].Invalidate( );
- }//寻找会议同步的全屏窗口
- try
- {
- CDialog * dlg = ( CDialog * )CWnd::FindWindow( "#32770" , "全屏窗口" );
- if( ::IsWindow( dlg->GetSafeHwnd( ) ) )
- dlg->EndDialog( IDOK );
- }
- catch( ... )
- {
- }//提示信息
- CTipDialog::ShowTip( "主持人退出了会议,会议结束" );
- }//从会议列表中删除该会议
- this->dlgBar.m_clist.DeleteItem( index );
- }//会议室列表
- if( ( index = this->dlgBar.m_rlist.FindItem( &info ) ) >= 0 )
- {
- CString text = this->dlgBar.m_rlist.GetItemText( index , 0 );
- this->dlgBar.m_rlist.DeleteItem( index );
- CTipDialog::ShowTip( "用户 " + text + "退出了会议" );
- }
- }//否则
- else
- { //有人加入了我的会议
- if( ! theApp.GetClient( ).GetConferenceName( ).empty( ) && res->data_name == theApp.GetClient( ).GetConferenceName( ) )
- { //会议室中没有该用户
- if( ( index = this->dlgBar.m_rlist.FindItem( &info ) ) < 0 )
- { //增加该用户
- index = this->dlgBar.m_rlist.InsertItem( 0 , res->user_name.c_str( ) );
- //提示加入了会议
- if( res->user_id != theApp.GetClient( ).GetUserID( ) && this->canTip )
- CTipDialog::ShowTip( "用户 " + ( CString )res->user_name.c_str( ) + "加入了会议" );
- }//停止发言
- if( res->user_id == theApp.GetClient( ).GetUserID( ) && ! res->isSpeeking && this->dlgBar.m_rlist.GetItemText( index , 1 ) == "是" )
- CTipDialog::ShowTip( "主持人停止了你发言" );
- //设定名称
- this->dlgBar.m_rlist.SetItemText( index , 1 , ( res->isCharement || res->isSpeeking ) ? "是" : "否" );
- //设定id
- this->dlgBar.m_rlist.SetItemData( index , res->user_id );
- }
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_STRING;
- info.psz = res->data_name.c_str( );
- //如果是新增会议,那么在会议列表中添加信息
- if( res->isCharement && this->dlgBar.m_clist.FindItem( &info ) < 0 )
- {
- index = this->dlgBar.m_clist.InsertItem( 0 , res->data_name.c_str( ) );
- this->dlgBar.m_clist.SetItemText( index , 1 , res->user_name.c_str( ) );
- this->dlgBar.m_clist.SetItemData( index , res->user_id );
- //如果是我创建会议的,那么最后一个视频窗口不可以显示图像
- if( res->user_id == theApp.GetClient( ).GetUserID( ) )
- ::SetWindowLong( this->videoDlg[ VIDEO_WND_NUMBER - 1 ].GetSafeHwnd( ) , GWL_USERDATA , true );
- //否则如果我是空闲的
- else if( theApp.GetClient( ).GetConferenceName( ).empty( ) && this->canTip )
- CTipDialog::ShowTip( "会议" + ( CString )res->data_name.c_str( ) + "刚刚创建" );
- }
- }
- }//只有我在会议中才可以
- if( ! theApp.GetClient( ).GetConferenceName( ).empty( ) )
- { //如果停止发言
- if( ! res->isSpeeking )
- {
- PVideoData vd;
- vd.user_id = res->user_id;
- vd.video = "停止发言";
- vd.size = strlen( vd.video );
- vd.type = PVideoData::VIDEO_DATA;
- //停止发言
- this->OnVideoData( &vd );
- }//通知会议成员发生了改变
- if( this->dlgBar.m_tab.GetCurSel( ) == 2 )
- this->dlgBar.OnItemchangedRecipientList( NULL , NULL );
- }
- }
- //加入会议请求
- bool CMainFrame::OnJoinDataNodeREQ( void * package )
- {
- PJoinDataNodeREQ * req = ( PJoinDataNodeREQ * )package;
- this->ShowWindow( SW_SHOW );
- this->ShowWindow( SW_SHOWMAXIMIZED );
- this->SetForegroundWindow( );
- CString text;
- text.Format( "用户 %s 请求加入会议nn你是否同意他加入你的会议?" , req->user_name.c_str( ) );
- return MessageBox( text , "视频会议" , MB_ICONINFORMATION | MB_YESNO ) == IDYES;
- }
- //加入会议回复
- bool CMainFrame::OnJoinDataNodeRES( void * package )
- {
- PJoinDataNodeRES * res = ( PJoinDataNodeRES * )package;
- //查找等待窗口
- CDialog * dlg = ( CDialog * )CWnd::FindWindow( "#32770" , "等待主持人的回复,请等待..." );
- if( dlg )
- {
- dlg->EndDialog( IDOK );
- if( ! res->success )
- MessageBox( "主持人拒绝你加入他的会议,请在会议列表中另选会议" , "视频会议" , MB_ICONINFORMATION | MB_OK );
- else
- {
- this->canTip = false;
- //一分钟之后才会有提示窗口
- this->SetTimer( 3 , 60000 , NULL );
- return true;
- }
- }
- return false;
- }
- //邀请用户加入会议请求
- const char * CMainFrame::OnInviteUserREQ( void * package )
- {
- PInviteUserREQ * req = ( PInviteUserREQ * )package;
- //找出主持人的信息
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = req->charement_id;
- int index = this->dlgBar.m_clist.FindItem( &info );
- //邀请加入
- if( index >= 0 )
- {
- static CString s;
- s = this->dlgBar.m_clist.GetItemText( index , 0 );
- if( req->prompt )
- return MessageBox( "用户 " + this->dlgBar.m_olist.GetItemText( index , 0 ) + " 邀请你加入他的会议n你是否要加入?" , "视频会议" , MB_ICONINFORMATION | MB_OKCANCEL ) == IDOK ? ( const char * )s : "";
- else
- {
- CTipDialog::ShowTip( "用户 " + this->dlgBar.m_olist.GetItemText( index , 0 ) + " 邀请你加入他的会议n你加入了他的会议" );
- this->canTip = false;
- //一分钟之后才会有提示窗口
- this->SetTimer( 3 , 60000 , NULL );
- return ( const char * )s;
- }
- }
- return "";
- }
- //邀请用户加入会议回复
- void CMainFrame::OnInviteUserRES( void * package )
- {
- PInviteUserRES * res = ( PInviteUserRES * )package;
- if( ! res->ireturn )
- { //找出该用户信息
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = res->user_id;
- int index = this->dlgBar.m_olist.FindItem( &info );
- if( index >= 0 )
- CTipDialog::ShowTip( "邀请用户" + this->dlgBar.m_olist.GetItemText( index , 0 ) + "失败,对方正在接收广播或者已经在别的会议中" );
- }
- }
- //申请发言
- int CMainFrame::OnSendAudioREQ( void * package )
- {
- PSendAudioREQ * req = ( PSendAudioREQ * )package;
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = req->user_id;
- int index = this->dlgBar.m_rlist.FindItem( &info );
- if( index >= 0 )
- {
- CString name = this->dlgBar.m_rlist.GetItemText( index , 0 );
- //先判断视频窗口是否够用且该用户是否已经获得了发言权
- int id = 0;
- bool ret = false;
- for( int i = 0 ; i < VIDEO_WND_NUMBER ; i ++ )
- {
- id = ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA );
- //该用户已经获得了发言权
- if( id == req->user_id )
- return -1;
- else if( id == 0 )
- ret = true;
- }
- if( ! ret )
- {
- CTipDialog::ShowTip( "会议成员" + name + "申请发言,但是因为视频窗口不够显示而失败nn想要让该用户发言,请先停止某个正在发言的用户" );
- return 0;
- }
- return MessageBox( "用户 " + name + " 申请发言,你是否同意其发言?" , "视频会议" , MB_ICONQUESTION | MB_YESNO ) == IDYES;
- }
- return 0;
- }
- //申请发言回复
- bool CMainFrame::OnSendAudioRES( void * package )
- {
- PSendAudioRES * res = ( PSendAudioRES * )package;
- //查找等待窗口
- CDialog * dlg = ( CDialog * )CWnd::FindWindow( "#32770" , "等待主持人的回复,请等待..." );
- if( ::IsWindow( dlg->GetSafeHwnd( ) ) )
- {
- dlg->EndDialog( IDOK );
- if( ! res->success )
- CTipDialog::ShowTip( "主持人拒绝你发言" );
- else
- CTipDialog::ShowTip( "主持人同意你发言,你可以发言了" );
- return res->success;
- }
- return false;
- }
- //视频窗口
- int CMainFrame::OnVideoData( void * package )
- {
- if( ! ::IsWindow( this->dlgBar.GetSafeHwnd( ) ) ) return NULL;
- PVideoData * vd = ( PVideoData * )package;
- //查找窗口名称
- CString wnd_name;
- //查找用户
- LVFINDINFO info;
- memset( &info , 0 , sizeof( info ) );
- info.flags = LVFI_PARAM;
- info.lParam = vd->user_id;
- //从在线用户查找用户名
- int index = this->dlgBar.m_olist.FindItem( &info );
- if( index >= 0 )
- wnd_name = this->dlgBar.m_olist.GetItemText( index , 0 );
- //视频信息
- if( vd->video )
- { //给窗口句柄显示图像
- if( vd->type == PVideoData::VIDEO_HEADER )
- {
- CWnd * pWnd = NULL;
- for( int i = 0; i < VIDEO_WND_NUMBER ; i ++ )
- if( ! ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA ) )
- {
- pWnd = &this->videoDlg[ i ]; break;
- }
- if( pWnd )
- {
- ::SetWindowLong( pWnd->GetSafeHwnd( ) , GWL_USERDATA , vd->user_id );
- pWnd->SetWindowText( wnd_name );
- return ( int )pWnd->GetSafeHwnd( );
- }
- CTipDialog::ShowTip( "没有足够的视频窗口供显示用户"+ wnd_name +"的视频,请先停止掉其他用户的视频数据再试" );
- return NULL;
- }//清除窗口句柄
- else if( vd->type == PVideoData::VIDEO_DATA )
- {
- for( int i = 0 ; i < VIDEO_WND_NUMBER ; i ++ )
- if( ::GetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == vd->user_id )
- {
- this->videoDlg[ i ].SetWindowText( "" );
- ::SetWindowLong( this->videoDlg[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->videoDlg[ i ].Invalidate( );
- break;
- }
- }
- }
- else
- CTipDialog::ShowTip( wnd_name + "没有视频数据" );
- return NULL;
- }
- // 窗口最小化时使用托盘
- void CMainFrame::OnSysCommand(UINT nID, LPARAM lParam)
- {
- CFrameWnd::OnSysCommand( nID, lParam );
- NOTIFYICONDATA tnd;
- tnd.cbSize = sizeof( NOTIFYICONDATA );
- tnd.hWnd=this->m_hWnd;
- tnd.uID = IDR_MAINFRAME;
- tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
- tnd.uCallbackMessage = WM_TRACER_MESSAGE;
- tnd.hIcon = LoadIcon( AfxGetInstanceHandle() , MAKEINTRESOURCE( IDR_MAINFRAME ) );
- strcpy( tnd.szTip , "视频会议客户端" );
- //最小化,向任务栏添加图标
- if( nID == SC_MINIMIZE )
- {
- this->ShowWindow( SW_HIDE );
- Shell_NotifyIcon( NIM_ADD , &tnd );
- ::SetProp( this->GetSafeHwnd( ) , "__hide_window__" , ( void * )1 );
- }
- //最大化
- else
- {
- ::SetProp( this->GetSafeHwnd( ) , "__hide_window__" , 0 );
- Shell_NotifyIcon( NIM_DELETE , &tnd );
- }
- }
- //托盘处理
- void CMainFrame::OnTrace( WPARAM wParam , LPARAM lParam )
- {
- if( lParam == WM_LBUTTONDOWN )
- {
- if( ::GetProp( this->GetSafeHwnd( ) , "__hide_window__" ) )
- {
- ::SetProp( this->GetSafeHwnd( ) , "__hide_window__" , 0 );
- this->ShowWindow( SW_SHOW );
- this->ShowWindow( SW_SHOWMAXIMIZED );
- this->SetForegroundWindow( );
- }
- else
- this->SendMessage( WM_SYSCOMMAND , SC_MINIMIZE );
- }
- }
- void CMainFrame::OnAddUser( WPARAM wParam , LPARAM lParam )
- {
- for( int i = 0; i < this->dlgBar.m_rlist.GetItemCount( ) ; i ++ )
- AddUser( ( CWnd * )wParam , ( char * )( const char * )this->dlgBar.m_rlist.GetItemText( i , 0 ) , this->dlgBar.m_rlist.GetItemData( i ) );
- }
- //关闭窗口
- void CMainFrame::OnDestroy()
- {
- NOTIFYICONDATA tnd;
- tnd.cbSize = sizeof( NOTIFYICONDATA );
- tnd.hWnd=this->m_hWnd;
- tnd.uID = IDR_MAINFRAME;
- tnd.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP;
- tnd.uCallbackMessage = WM_TRACER_MESSAGE;
- tnd.hIcon = LoadIcon( AfxGetInstanceHandle() , MAKEINTRESOURCE( IDR_MAINFRAME ) );
- strcpy( tnd.szTip , "视频会议客户端" );
- Shell_NotifyIcon( NIM_DELETE , &tnd );
- if( ! theApp.GetClient( ).GetConferenceName().empty( ) )
- //发送退出会议
- theApp.GetClient( ).SendExitDataNode( );
- CFrameWnd::OnDestroy( );
- }
- //定时发包
- void CMainFrame::OnTimer(UINT nIDEvent)
- {
- CFrameWnd::OnTimer(nIDEvent);
- //每隔2分钟发送一次测试网络连接的数据包
- if( nIDEvent == 1 )
- {
- // theApp.GetClient( ).SendTestConnect( );
- }
- else if( nIDEvent == 2 )
- {
- static time_t i = 0;
- CTimeSpan tm( i ++ );
- CString text;
- text.Format( "视频会议系统 - 用户名: %s 会议名: %s 时间: %s" , theApp.GetClient( ).GetUserName( ) , theApp.GetClient( ).GetConferenceName( ).c_str( ) , theApp.GetClient( ).GetConferenceName( ).empty( ) ? "" : tm.Format( "%H:%M:%S") );
- if( theApp.GetClient( ).GetConferenceName( ).empty( ) )
- {
- i = 0; this->KillTimer( 2 );
- }
- this->SetWindowText( text );
- }
- else if( nIDEvent == 3 )
- {
- this->KillTimer( 3 );
- this->canTip = true;
- }
- }
- // 关闭窗口
- void CMainFrame::OnClose()
- {
- if( theApp.GetClient( ).GetTCP( false ).IsConnected( ) && MessageBox( "你确定要退出视频会议系统吗?" , "视频会议客户端" , MB_ICONINFORMATION | MB_YESNO ) == IDNO )
- return;
- CTipDialog::canShow = false;
- CSizingControlBar::GlobalSaveState( this , "video_window" );
- CFrameWnd::OnClose( );
- }