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

IP电话/视频会议

开发平台:

Visual C++

  1. // WBWnd.cpp: implementation of the CWBWnd class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "..WB.h"
  6. #include "WBWnd.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. //////////////////////////////////////////////////////////////////////
  13. // Construction/Destruction
  14. //////////////////////////////////////////////////////////////////////
  15. CWBWnd::CWBWnd( CDrawView * view , bool m_bRect , bool m_bCapture ) : CDraw( view ) , CDialog( IDD_CAPTURE_DIALOG )
  16. {
  17. //{{AFX_DATA_INIT(CWBWnd)
  18. //}}AFX_DATA_INIT
  19. this->m_bDown = false;
  20. this->type = WBWND;
  21. this->screenDC = NULL;
  22. this->m_bRect = m_bRect;
  23. if( this->pen.GetSafeHandle( ) )
  24. this->pen.DeleteObject( );
  25. this->pen.CreatePen( PS_DOT , 1 , RGB( 0 , 0 , 0 ) );
  26. if( this->brush.GetSafeHandle( ) )
  27. this->brush.DeleteObject( );
  28. this->brush.CreateStockObject( NULL_BRUSH );
  29.     //如果是选择
  30. if( this->m_bRect )
  31. {
  32. ::Sleep( 100 );
  33. this->DoModal( );
  34. }
  35. else if( m_bCapture )
  36. this->view->SetCapture( );
  37. }
  38. CWBWnd::~CWBWnd( )
  39. {
  40. }
  41. void CWBWnd::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CWBWnd)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CWBWnd, CDialog)
  48. //{{AFX_MSG_MAP(CWBWnd)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. BOOL CWBWnd::OnInitDialog( ) 
  52. {
  53. CDialog::OnInitDialog( );
  54. ::SetClassLong( this->GetSafeHwnd( ) , GCL_HCURSOR , ( long )::AfxGetApp( )->LoadStandardCursor( MAKEINTRESOURCE( IDC_CROSS ) ) );
  55. //移动窗口
  56. this->MoveWindow( 0 , 0 , ::GetSystemMetrics( SM_CXSCREEN ) , ::GetSystemMetrics( SM_CYSCREEN ) );
  57. //把桌面的的图形捕捉过来
  58. ::Sleep( 100 );
  59. CWindowDC dc( CWnd::GetDesktopWindow( ) );
  60. this->screenDC = new CMemDC( &dc , false );
  61. return TRUE;
  62. }
  63. LRESULT CWBWnd::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) 
  64. {
  65. switch( message )
  66. {
  67. case WM_LBUTTONDOWN :
  68. {
  69. this->start.x = LOWORD(lParam);
  70. this->start.y = HIWORD(lParam);
  71. }
  72. break;
  73. case WM_MOUSEMOVE :
  74. if( wParam & MK_LBUTTON )
  75. {
  76. this->end.x = LOWORD(lParam);
  77. this->end.y = HIWORD(lParam);
  78. this->Invalidate( );
  79. }
  80. break;
  81. case WM_LBUTTONUP :
  82. {
  83. if( this->wndBitmap.GetSafeHandle( ) ) this->wndBitmap.DeleteObject( );
  84. if( this->wndDC.GetSafeHdc( ) ) this->wndDC.DeleteDC( );
  85. this->wndDC.CreateCompatibleDC( this->screenDC );
  86. CRect rc( this->start , this->end );
  87. this->wndBitmap.CreateCompatibleBitmap( this->screenDC , rc.Width( ) , rc.Height( ) );
  88. this->wndDC.SelectObject( &this->wndBitmap );
  89. this->wndDC.BitBlt( 0 , 0 , rc.Width( ) , rc.Height( ) , this->screenDC , rc.left  , rc.top , SRCCOPY );
  90. if( this->rgn.GetSafeHandle( ) )
  91. this->rgn.DeleteObject( );
  92. this->rgn.CreateRectRgn( 0 , 0 , rc.Width( ) , rc.Height( ) );
  93. CPoint point = this->view->GetScrollPosition( );
  94. this->rgn.OffsetRgn( point );
  95. delete this->screenDC; this->screenDC = NULL;
  96. this->SendMessage( WM_CLOSE );
  97. this->Draw( );
  98. this->view->Invalidate( );
  99. ::Sleep( 100 );
  100. this->view->PostMessage( WM_LBUTTONUP , wParam , MAKEWPARAM( point.x , point.y ) );
  101. }
  102. break;
  103. case WM_PAINT :
  104. if( this->screenDC )
  105. {
  106. CPaintDC dc( this );
  107. dc.BitBlt( 0 , 0 , ::GetSystemMetrics( SM_CXSCREEN ) , ::GetSystemMetrics( SM_CYSCREEN ) , this->screenDC , 0 , 0 , SRCCOPY );
  108. if( this->start != this->end ) 
  109. {
  110. CMemDC memDC( &dc );
  111. CRect rc( this->start , this->end );
  112. memDC.SelectObject( &this->pen );
  113. memDC.SelectObject( &this->brush );
  114. memDC.Rectangle( &rc );
  115. }
  116. }
  117. break;
  118. case WM_ERASEBKGND :
  119. return true;
  120. }
  121. return CDialog::WindowProc(message, wParam, lParam);
  122. }
  123. void CWBWnd::LButtonDown( UINT nFlags , CPoint point )
  124. {
  125. }
  126. void CWBWnd::LButtonUp( UINT nFlags , CPoint point )
  127. {
  128. if( ! this->m_bRect )
  129. {
  130. this->CaptureBitmap( );
  131. ::ReleaseCapture( );
  132. }
  133. }
  134. void CWBWnd::MouseMove( UINT nFlags , CPoint point )
  135. {
  136. }
  137. CDC * CWBWnd::Draw( CDC * pDC )
  138. {
  139. if( pDC == NULL )
  140. pDC = this->view->GetMemDC( );
  141. if( this->rgn.GetSafeHandle( ) )
  142. {
  143. CRect rc;
  144. this->rgn.GetRgnBox( &rc );
  145. if( ! this->wndDC.GetSafeHdc( ) && this->wndBitmap.GetSafeHandle( ) )
  146. {
  147. this->wndDC.CreateCompatibleDC( pDC );
  148. this->wndDC.SelectObject( &this->wndBitmap );
  149. }
  150. pDC->BitBlt( rc.left , rc.top , rc.Width( ) , rc.Height( ) , &this->wndDC , 0 , 0 , SRCCOPY );
  151. }
  152. return pDC;
  153. }
  154. void CWBWnd::CaptureBitmap( void )
  155. {
  156. if( this->wndBitmap.GetSafeHandle( ) )
  157. this->wndBitmap.DeleteObject( );
  158. if( this->wndDC.GetSafeHdc( ) )
  159. this->wndDC.DeleteDC( );
  160. CPoint point;
  161. ::GetCursorPos( &point );
  162. CWnd * pWnd = CWnd::WindowFromPoint( point );
  163. if( ! pWnd )
  164. pWnd = CWnd::GetDesktopWindow( );
  165. CWindowDC dc( pWnd );
  166. this->wndDC.CreateCompatibleDC( &dc );
  167. CRect rc;
  168. pWnd->GetWindowRect( &rc );
  169. this->wndBitmap.CreateCompatibleBitmap( &dc , rc.Width( ) , rc.Height( ) );
  170. this->wndDC.SelectObject( &this->wndBitmap );
  171. this->wndDC.BitBlt( 0 , 0 , rc.Width( ) , rc.Height( ) , &dc , 0 , 0 , SRCCOPY );
  172. if( this->rgn.GetSafeHandle( ) )
  173. this->rgn.DeleteObject( );
  174. this->rgn.CreateRectRgn( 0 , 0 , rc.Width( ) , rc.Height( ) );
  175. point = this->view->GetScrollPosition( );
  176. this->rgn.OffsetRgn( point );
  177. this->Draw( );
  178. this->view->Invalidate( );
  179. }
  180. CBitmap * CWBWnd::GetBitmap( void )
  181. {
  182. if( ! this->wndBitmap.GetSafeHandle( ) )
  183. {
  184. if( ! this->rgn.GetSafeHandle( ) )
  185. return NULL;
  186. CRect rc;
  187. this->rgn.GetRgnBox( &rc );
  188. this->wndBitmap.CreateCompatibleBitmap( this->view->GetMemDC( ) , rc.Width( ) , rc.Height( ) );
  189. }
  190. return & this->wndBitmap;
  191. }