ControlDlg.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:6k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // ControlDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Control.h"
- #include "ControlDlg.h"
- #include "VideoDlg.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- extern CControlApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CControlDlg dialog
- CControlDlg::CControlDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CControlDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CControlDlg)
- //}}AFX_DATA_INIT
- }
- void CControlDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CControlDlg)
- DDX_Control(pDX, IDC_AUTO_STATIC, m_astatic);
- DDX_Control(pDX, IDC_ONLINE_STATIC, m_ostatic);
- DDX_Control(pDX, IDC_LIST, m_olist);
- DDX_Control(pDX, IDC_VIEW_BUTTON, m_viewbtn);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CControlDlg, CDialog)
- //{{AFX_MSG_MAP(CControlDlg)
- ON_BN_CLICKED(IDC_VIEW_BUTTON, OnViewButton)
- ON_WM_SIZE()
- ON_WM_CLOSE()
- ON_WM_CTLCOLOR()
- ON_NOTIFY(NM_DBLCLK, IDC_LIST, OnDblclkList)
- ON_WM_TIMER()
- ON_WM_NCHITTEST()
- //}}AFX_MSG_MAP
- ON_MESSAGE( WM_PACKAGE , OnPackage )
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CControlDlg message handlers
- BOOL CControlDlg::OnInitDialog( )
- {
- CDialog::OnInitDialog( );
- this->m_olist.SetExtendedStyle( LVS_EX_FULLROWSELECT );
- CRect rc;
- this->m_olist.GetClientRect( &rc );
- this->m_olist.InsertColumn( 0 , "用户名" , LVCFMT_LEFT , rc.Width( ) );
- CThread::Run( CControlApp::OnConnect , this );
- //启动定时器为2分钟
- // this->SetTimer( 1 , 120000 , NULL );
- return TRUE;
- }
- UINT CControlDlg::OnNcHitTest(CPoint point)
- {
- UINT hitTest = CDialog::OnNcHitTest(point);
- return hitTest == HTCLIENT ? HTCAPTION : hitTest;
- }
- void CControlDlg::OnTimer(UINT nIDEvent)
- {
- CDialog::OnTimer( nIDEvent );
- /*
- if( nIDEvent == 1 && theApp.GetTCP( false ).IsConnected( ) )
- {
- PConnectTest test;
- test.assembleData( 0 );
- theApp.GetTCP( ).Send( test.buffer );
- }
- */
- }
- HBRUSH CControlDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- static HBRUSH b = ::CreateSolidBrush( RGB( 214 , 239 , 255 ) );
- pDC->SetBkMode( TRANSPARENT );
- return b;
- }
- void CControlDlg::OnSize(UINT nType, int cx, int cy)
- {
- CDialog::OnSize( nType , cx , cy );
- if( this->m_astatic )
- this->m_astatic.MoveWindow( 0 , 0 , cx , cy );
- if( this->m_ostatic )
- this->m_ostatic.MoveWindow( 0 , 0 , cx , cy - 40 );
- if( this->m_olist )
- this->m_olist.MoveWindow( 0 , 20 , cx , cy - 60 );
- if( this->m_viewbtn )
- this->m_viewbtn.MoveWindow( cx / 2 - 50 , cy - 30 , 100 , 25 );
- }
- void CControlDlg::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
- {
- this->OnViewButton( );
- *pResult = 0;
- }
- void CControlDlg::OnViewButton()
- {
- POSITION pos = this->m_olist.GetFirstSelectedItemPosition( );
- if( ! pos )
- {
- MessageBox( "请从列表中选择一个查看点" , "云台镜头控制" , MB_ICONSTOP | MB_OK );
- return;
- }
- int index = this->m_olist.GetNextSelectedItem( pos );
- //取出用户id
- int user_id = this->m_olist.GetItemData( index );
- CVideoDlg * dlg = NULL;
- INT_PTR_MAP::iterator itr = theApp.GetMap( )->find( user_id );
- if( itr != theApp.GetMap( )->end( ) )
- {
- dlg = ( CVideoDlg * )itr->second;
- dlg->ShowWindow( SW_RESTORE );
- dlg->SetForegroundWindow( );
- return;
- }
- dlg = new CVideoDlg( CWnd::GetDesktopWindow( ) );
- dlg->Create( CVideoDlg::IDD , CWnd::GetDesktopWindow( ) );
- dlg->user_id = user_id;
- //窗口标题
- dlg->SetWindowText( this->m_olist.GetItemText( index , 0 ) );
- //保存在列表中
- ( * theApp.GetMap( ) )[ dlg->user_id ] = dlg;
- //发送视频请求
- PRecvVideoREQ req;
- req.assembleData( user_id );
- theApp.GetTCP( ).Send( req.buffer );
- }
- void CControlDlg::OnClose()
- {
- if( this->m_astatic.IsWindowVisible( ) )
- {
- if( MessageBox( "正在连接服务器,要退出云台镜头控制客户端吗?" , "云台镜头控制" , MB_ICONQUESTION | MB_YESNO ) == IDNO )
- return;
- }
- else
- {
- if( MessageBox( "确定要退出云台镜头控制客户端吗?" , "云台镜头控制" , MB_ICONQUESTION | MB_YESNO ) == IDNO )
- return;
- }
- CDialog::OnCancel( );
- }
- void CControlDlg::OnPackage( WPARAM wParam , LPARAM lParam )
- {
- CDataPackage * dp = ( CDataPackage * )wParam;
- if( ! dp )
- { //遍历所有视频窗口列表
- for( INT_PTR_MAP::iterator itr = theApp.GetMap( )->begin( ); itr != theApp.GetMap( )->end( ); itr ++ )
- ( ( CVideoDlg * )itr->second )->DestroyWindow( );
- theApp.GetMap( )->clear( );
- this->m_astatic.ShowWindow( SW_SHOW );
- this->m_olist.DeleteAllItems( );
- this->m_olist.ShowWindow( SW_HIDE );
- this->m_viewbtn.ShowWindow( SW_HIDE );
- CThread::Run( CControlApp::OnConnect , this );
- return;
- }
- switch( dp->Tag )
- {
- case POnlineUserRESTAG :
- {
- POnlineUserRES * res = ( POnlineUserRES * )dp;
- LVFINDINFO info;
- info.psz = res->user_name.c_str( );
- info.lParam = res->user_id;
- info.flags = res->user_name.empty( ) ? LVFI_PARAM : LVFI_STRING;
- //查找
- int index = this->m_olist.FindItem( &info );
- //增加
- if( index < 0 && ! res->user_name.empty( ) )
- {
- index = this->m_olist.InsertItem( this->m_olist.GetItemCount( ) , res->user_name.c_str( ) );
- this->m_olist.SetItemData( index , res->user_id );
- }//退出
- if( index >= 0 && res->user_name.empty( ) )
- { //从用户列表中删除
- this->m_olist.DeleteItem( index );
- INT_PTR_MAP * m_map = theApp.GetMap( );
- INT_PTR_MAP::iterator itr = m_map->find( res->user_id );
- //从视频列表中删除
- if( itr != m_map->end( ) )
- {
- CVideoDlg * dlg = ( CVideoDlg * )itr->second;
- dlg->DestroyWindow( );
- ::Sleep( 100 );
- if( ( itr = m_map->find( res->user_id ) ) != m_map->end( ) )
- m_map->erase( itr );
- }
- }
- }break;
- }
- }