MonitorDialog.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:7k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // MonitorDialog.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Monitor.h"
- #include "MonitorDialog.h"
- #include "ConectDialog.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- #define ROW_NUMBER 3
- #define COLUMN_NUMBER 3
- extern CMonitorApp theApp;
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorDialog dialog
- CMonitorDialog::CMonitorDialog(CWnd* pParent /*=NULL*/)
- : CDialog(CMonitorDialog::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CMonitorDialog)
- //}}AFX_DATA_INIT
- this->fullWnd = NULL;
- this->orgRect = CRect( 0 , 0 , 0 , 0 );
- }
- void CMonitorDialog::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CMonitorDialog)
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CMonitorDialog, CDialog)
- //{{AFX_MSG_MAP(CMonitorDialog)
- ON_WM_CTLCOLOR()
- ON_WM_TIMER()
- //}}AFX_MSG_MAP
- ON_MESSAGE( WM_CONNECT_MESSAGE , OnConnect )
- ON_MESSAGE( WM_VIDEO_MESSAGE , OnVideoData )
- ON_MESSAGE( WM_WINDOW , OnWindow )
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CMonitorDialog message handlers
- BOOL CMonitorDialog::OnInitDialog()
- {
- CDialog::OnInitDialog();
- this->InitInterface( );
- this->PostMessage( WM_CONNECT_MESSAGE );
- //一分钟
- this->SetTimer( 1 , 60000 , NULL );
- return TRUE;
- }
- //定时判断窗口状态
- void CMonitorDialog::OnTimer(UINT nIDEvent)
- {
- CDialog::OnTimer(nIDEvent);
- if( nIDEvent == 1 )
- {
- int id = 0;
- for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
- {
- if( ( id = ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) ) )
- {
- if( this->video[ i ].GetDlgCtrlID( ) == 1 )
- { //发送请求视频数据
- PRecvVideoREQ req;
- req.assembleData( id );
- theApp.GetTCP( ).Send( req.buffer );
- }
- else
- this->video[ i ].SetDlgCtrlID( 1 );
- }
- }
- }
- }
- //程序退出
- void CMonitorDialog::OnCancel( void )
- {
- if( MessageBox( "确定要退出监控系统吗?" , "视频监控" , MB_ICONINFORMATION | MB_YESNO ) == IDYES )
- CDialog::OnCancel( );
- }
- //初始化界面
- void CMonitorDialog::InitInterface( void )
- {
- HICON m_hIcon = AfxGetApp( )->LoadIcon( IDR_MAINFRAME );
- this->SetIcon( m_hIcon , TRUE );
- this->SetIcon( m_hIcon , FALSE );
- this->SetWindowText( "视频监控系统" );
- for( int i = 0; i < 9 ; i ++ )
- this->video[ i ].SubclassDlgItem( IDC_1_STATIC + i , this );
- int width = ::GetSystemMetrics( SM_CXSCREEN );
- int height = ::GetSystemMetrics( SM_CYSCREEN );
- this->MoveWindow( 0 , 0 , width , height );
- CRect rc;
- this->GetClientRect( &rc );
- int wnd_width = rc.Width( ) / ROW_NUMBER;
- int wnd_height = rc.Height( ) / COLUMN_NUMBER;
- for( i = 0; i < ROW_NUMBER ; i ++ )
- for( int j = 0 ; j < COLUMN_NUMBER ; j ++ )
- this->video[ i * ROW_NUMBER + j ].MoveWindow( j * wnd_width , i * wnd_height , wnd_width - 1 , wnd_height - 1 );
- }
- //连接线程
- void CMonitorDialog::OnConnect( WPARAM wParam , LPARAM lParam )
- {
- for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
- {
- ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->video[ i ].SetWindowText( "无 视 频 信 号" );
- this->video[ i ].Invalidate( );
- }
- CConectDialog dlg;
- static int times = 0;
- //延时5秒钟
- if( times )
- ::Sleep( 5000 );
- times ++;
- CThread::Run( CMonitorApp::OnInit , &dlg );
- dlg.DoModal( );
- if( dlg.m_return )
- this->EndDialog( IDOK );
- }
- //视频显示通知
- int CMonitorDialog::OnVideoData( WPARAM wParam , LPARAM lParam )
- {
- CDataPackage * dp = ( CDataPackage * )wParam;
- //显示该用户的视频图像
- if( dp->Tag == PVideoDataTAG )
- {
- PVideoData * vd = ( PVideoData * )dp;
- if( vd->type == PVideoData::VIDEO_HEADER && vd->video && vd->size )
- for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
- if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == vd->user_id )
- {
- CVideoUSB * v = new CVideoUSB( );
- if( ! v->InitDraw( this->video[ i ].GetSafeHwnd( ) , vd->video , vd->size ) )
- {
- ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->video[ i ].SetWindowText( "无 视 频 信 号" );
- delete v;
- return NULL;
- }
- return ( int )v;
- }
- }
- else if( dp->Tag == POnlineUserRESTAG )
- {
- POnlineUserRES * res = ( POnlineUserRES * )dp;
- //请求显示
- if( ! res->user_name.empty( ) )
- { //找到监控窗口
- if( ! ::GetWindowLong( this->video[ lParam ].GetSafeHwnd( ) , GWL_USERDATA ) )
- { //设定窗口号
- ::SetWindowLong( this->video[ lParam ].GetSafeHwnd( ) , GWL_USERDATA , res->user_id );
- //设定窗口名称
- this->video[ lParam ].SetWindowText( res->user_name.c_str( ) );
- return true;
- }
- }//停止显示该用户的视频图像
- else
- {
- for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
- if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == res->user_id )
- {
- ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
- this->video[ i ].SetWindowText( "无 视 频 信 号" );
- this->video[ i ].Invalidate( );
- break;
- }
- }
- }
- return false;
- }
- void CMonitorDialog::OnWindow( WPARAM wParam , LPARAM lParam )
- {
- PPanelCommand * cmd = ( PPanelCommand * )wParam;
- int total = ROW_NUMBER * COLUMN_NUMBER;
- //恢复窗口
- if( this->fullWnd )
- {
- this->fullWnd->MoveWindow( this->orgRect );
- for( int i = 0; i < total; i ++ )
- this->video[ i ].ShowWindow( SW_SHOW );
- }
- for( int i = 0; i < total ; i ++ )
- if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == cmd->user_id )
- {
- if( this->video[ i ].GetSafeHwnd( ) == this->fullWnd->GetSafeHwnd( ) )
- this->fullWnd = NULL;
- else
- {
- for( int j = 0; j < total; j ++ )
- this->video[ j ].ShowWindow( SW_HIDE );
- this->fullWnd = &this->video[ i ];
- this->fullWnd->GetWindowRect( &this->orgRect );
- this->ScreenToClient( &this->orgRect );
- CRect rc;
- this->GetClientRect( &rc );
- this->fullWnd->SetWindowPos( &CWnd::wndTop , 0 , 0 , rc.Width( ) , rc.Height( ) , SWP_SHOWWINDOW | SWP_NOACTIVATE );
- }
- break;
- }
- }
- //颜色设定
- HBRUSH CMonitorDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- pDC->SetBkMode( TRANSPARENT );
- pDC->SetTextColor( RGB( 255 , 0 , 0 ) );
- static HBRUSH hVideo = ::CreateSolidBrush( RGB( 10 , 10 , 10 ) );
- return nCtlColor == CTLCOLOR_STATIC ? hVideo : hbr;
- }