MonitorDialog.cpp
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:7k
源码类别:

IP电话/视频会议

开发平台:

Visual C++

  1. // MonitorDialog.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Monitor.h"
  5. #include "MonitorDialog.h"
  6. #include "ConectDialog.h"
  7. #ifdef _DEBUG
  8. #define new DEBUG_NEW
  9. #undef THIS_FILE
  10. static char THIS_FILE[] = __FILE__;
  11. #endif
  12. #define   ROW_NUMBER         3
  13. #define   COLUMN_NUMBER      3
  14. extern CMonitorApp theApp;
  15. /////////////////////////////////////////////////////////////////////////////
  16. // CMonitorDialog dialog
  17. CMonitorDialog::CMonitorDialog(CWnd* pParent /*=NULL*/)
  18. : CDialog(CMonitorDialog::IDD, pParent)
  19. {
  20. //{{AFX_DATA_INIT(CMonitorDialog)
  21. //}}AFX_DATA_INIT
  22. this->fullWnd = NULL;
  23. this->orgRect = CRect( 0 , 0 , 0 , 0 );
  24. }
  25. void CMonitorDialog::DoDataExchange(CDataExchange* pDX)
  26. {
  27. CDialog::DoDataExchange(pDX);
  28. //{{AFX_DATA_MAP(CMonitorDialog)
  29. //}}AFX_DATA_MAP
  30. }
  31. BEGIN_MESSAGE_MAP(CMonitorDialog, CDialog)
  32. //{{AFX_MSG_MAP(CMonitorDialog)
  33. ON_WM_CTLCOLOR()
  34. ON_WM_TIMER()
  35. //}}AFX_MSG_MAP
  36. ON_MESSAGE( WM_CONNECT_MESSAGE , OnConnect )
  37. ON_MESSAGE( WM_VIDEO_MESSAGE , OnVideoData )
  38. ON_MESSAGE( WM_WINDOW , OnWindow )
  39. END_MESSAGE_MAP()
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CMonitorDialog message handlers
  42. BOOL CMonitorDialog::OnInitDialog()
  43. {
  44. CDialog::OnInitDialog();
  45. this->InitInterface( );
  46. this->PostMessage( WM_CONNECT_MESSAGE );
  47.     //一分钟
  48. this->SetTimer( 1 , 60000 , NULL );
  49.     
  50. return TRUE;
  51. }
  52. //定时判断窗口状态
  53. void CMonitorDialog::OnTimer(UINT nIDEvent) 
  54. {
  55. CDialog::OnTimer(nIDEvent);
  56. if( nIDEvent == 1 )
  57. {
  58. int id = 0;
  59. for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
  60. {
  61. if( ( id = ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) ) )
  62. {
  63. if( this->video[ i ].GetDlgCtrlID( ) == 1 )
  64. {   //发送请求视频数据
  65. PRecvVideoREQ req;
  66. req.assembleData( id );
  67. theApp.GetTCP( ).Send( req.buffer );
  68. }
  69. else
  70. this->video[ i ].SetDlgCtrlID( 1 );
  71. }
  72. }
  73. }
  74. }
  75. //程序退出
  76. void CMonitorDialog::OnCancel( void )
  77. {
  78. if( MessageBox( "确定要退出监控系统吗?" , "视频监控" , MB_ICONINFORMATION | MB_YESNO ) == IDYES )
  79. CDialog::OnCancel( );
  80. }
  81. //初始化界面
  82. void CMonitorDialog::InitInterface( void )
  83. {
  84. HICON m_hIcon = AfxGetApp( )->LoadIcon( IDR_MAINFRAME );
  85. this->SetIcon( m_hIcon , TRUE );
  86. this->SetIcon( m_hIcon , FALSE );
  87. this->SetWindowText( "视频监控系统" );
  88. for( int i = 0; i < 9 ; i ++ )
  89. this->video[ i ].SubclassDlgItem( IDC_1_STATIC + i , this );
  90. int width = ::GetSystemMetrics( SM_CXSCREEN );
  91. int height = ::GetSystemMetrics( SM_CYSCREEN );
  92. this->MoveWindow( 0 , 0 , width , height );
  93. CRect rc;
  94. this->GetClientRect( &rc );
  95. int wnd_width = rc.Width( ) / ROW_NUMBER;
  96. int wnd_height = rc.Height( ) / COLUMN_NUMBER;
  97. for( i = 0; i < ROW_NUMBER ; i ++ )
  98. for( int j = 0 ; j < COLUMN_NUMBER ; j ++ )
  99. this->video[ i * ROW_NUMBER + j ].MoveWindow( j * wnd_width , i * wnd_height , wnd_width - 1 , wnd_height - 1 );
  100. }
  101. //连接线程
  102. void CMonitorDialog::OnConnect( WPARAM wParam , LPARAM lParam )
  103. {
  104. for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
  105. {
  106. ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
  107. this->video[ i ].SetWindowText( "无  视  频  信  号" );
  108. this->video[ i ].Invalidate( );
  109. }
  110. CConectDialog dlg;
  111. static int times = 0;
  112.     //延时5秒钟
  113. if( times )
  114. ::Sleep( 5000 );
  115. times ++;
  116. CThread::Run( CMonitorApp::OnInit , &dlg );
  117. dlg.DoModal( );
  118. if( dlg.m_return )
  119. this->EndDialog( IDOK );
  120. }
  121. //视频显示通知
  122. int CMonitorDialog::OnVideoData( WPARAM wParam , LPARAM lParam )
  123. {
  124. CDataPackage * dp = ( CDataPackage * )wParam;
  125.     //显示该用户的视频图像
  126. if( dp->Tag == PVideoDataTAG )
  127. {
  128. PVideoData * vd = ( PVideoData * )dp;
  129. if( vd->type == PVideoData::VIDEO_HEADER && vd->video && vd->size )
  130. for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
  131. if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == vd->user_id )
  132. {
  133. CVideoUSB * v = new CVideoUSB( );
  134. if( ! v->InitDraw( this->video[ i ].GetSafeHwnd( ) , vd->video , vd->size ) )
  135. {
  136. ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
  137.     this->video[ i ].SetWindowText( "无  视  频  信  号" );
  138. delete v;
  139. return NULL;
  140. }
  141. return ( int )v;
  142. }
  143. }
  144. else if( dp->Tag == POnlineUserRESTAG )
  145. {
  146. POnlineUserRES * res = ( POnlineUserRES * )dp;
  147.         //请求显示   
  148. if( ! res->user_name.empty( ) )
  149. {    //找到监控窗口
  150. if( ! ::GetWindowLong( this->video[ lParam ].GetSafeHwnd( ) , GWL_USERDATA ) )
  151. {   //设定窗口号
  152. ::SetWindowLong( this->video[ lParam ].GetSafeHwnd( ) , GWL_USERDATA , res->user_id );
  153.                 //设定窗口名称
  154. this->video[ lParam ].SetWindowText( res->user_name.c_str( ) );
  155. return true;
  156. }
  157. }//停止显示该用户的视频图像
  158. else
  159. {
  160. for( int i = 0; i < COLUMN_NUMBER * ROW_NUMBER ; i ++ )
  161. if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == res->user_id )
  162. {
  163. ::SetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA , 0 );
  164. this->video[ i ].SetWindowText( "无  视  频  信  号" );
  165. this->video[ i ].Invalidate( );
  166. break;
  167. }
  168. }
  169. }
  170. return false;
  171. }
  172. void CMonitorDialog::OnWindow( WPARAM wParam , LPARAM lParam )
  173. {
  174. PPanelCommand * cmd = ( PPanelCommand * )wParam;
  175. int total =  ROW_NUMBER * COLUMN_NUMBER;
  176.     //恢复窗口
  177. if( this->fullWnd )
  178. {
  179. this->fullWnd->MoveWindow( this->orgRect );
  180. for( int i = 0; i < total; i ++ )
  181. this->video[ i ].ShowWindow( SW_SHOW );
  182. }
  183. for( int i = 0; i < total ; i ++ )
  184. if( ::GetWindowLong( this->video[ i ].GetSafeHwnd( ) , GWL_USERDATA ) == cmd->user_id )
  185. {
  186. if( this->video[ i ].GetSafeHwnd( ) == this->fullWnd->GetSafeHwnd( ) )
  187. this->fullWnd = NULL;
  188. else
  189. {
  190. for( int j = 0; j < total; j ++ )
  191. this->video[ j ].ShowWindow( SW_HIDE );
  192. this->fullWnd = &this->video[ i ];
  193. this->fullWnd->GetWindowRect( &this->orgRect );
  194. this->ScreenToClient( &this->orgRect );
  195. CRect rc;
  196. this->GetClientRect( &rc );
  197. this->fullWnd->SetWindowPos( &CWnd::wndTop , 0 , 0 , rc.Width( ) , rc.Height( ) , SWP_SHOWWINDOW | SWP_NOACTIVATE );
  198. }
  199. break;
  200. }
  201. }
  202. //颜色设定
  203. HBRUSH CMonitorDialog::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
  204. {
  205. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  206. pDC->SetBkMode( TRANSPARENT );
  207. pDC->SetTextColor( RGB( 255 , 0 , 0 ) );
  208. static HBRUSH hVideo = ::CreateSolidBrush( RGB( 10 , 10 , 10 ) );
  209. return nCtlColor == CTLCOLOR_STATIC ? hVideo : hbr;
  210. }