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

IP电话/视频会议

开发平台:

Visual C++

  1. // WBPen.cpp: implementation of the CWBPen class.
  2. //
  3. //////////////////////////////////////////////////////////////////////
  4. #include "stdafx.h"
  5. #include "..WB.h"
  6. #include "WBPen.h"
  7. #ifdef _DEBUG
  8. #undef THIS_FILE
  9. static char THIS_FILE[]=__FILE__;
  10. #define new DEBUG_NEW
  11. #endif
  12. #pragma comment( lib , "msimg32.lib" )
  13. //////////////////////////////////////////////////////////////////////
  14. // Construction/Destruction
  15. //////////////////////////////////////////////////////////////////////
  16. CWBPen::CWBPen( CDrawView * view , int ps ) : CDraw( view )
  17. {
  18. this->type = ! ps ? PEN : PEN1;
  19. CDC * pDC = this->view->GetMemDC( );
  20. this->memDC.CreateCompatibleDC( pDC );
  21. this->bitmap.CreateCompatibleBitmap( pDC , this->dcSize.cx , this->dcSize.cy );
  22. this->memDC.SelectObject( &this->bitmap );
  23. this->memDC.FillSolidRect( 0 , 0 , this->dcSize.cx , this->dcSize.cy , this->memDC.GetBkColor( ) );
  24. }
  25. CWBPen::~CWBPen()
  26. {
  27. }
  28. void CWBPen::LButtonDown( UINT nFlags , CPoint point )
  29. {
  30. CDraw::LButtonDown( nFlags , point );
  31. if( nFlags & MK_LBUTTON )
  32. {
  33. this->memDC.SelectObject( &this->pen );
  34. this->memDC.MoveTo( point );
  35. this->view->GetMemDC( )->MoveTo( point );
  36. this->start = this->end = point;
  37. }
  38. }
  39. void CWBPen::LButtonUp( UINT nFlags , CPoint point )
  40. {
  41. CWaitCursor cursor;
  42. int width = this->GetWidth( );
  43. this->start.Offset( - width , - width );
  44. this->end.Offset( width , width );
  45. CRect rc( this->start , this->end );
  46. rc.NormalizeRect( );
  47. if( this->rgn.GetSafeHandle( ) )
  48. this->rgn.DeleteObject( );
  49. this->rgn.CreateRectRgn( 0 , 0 , 0 , 0 );
  50. CRgn r;
  51. int color = this->memDC.GetBkColor( );
  52. for( int h = rc.top; h < rc.bottom; h ++ )
  53. for( int w = rc.left; w < rc.right; w ++ )
  54. if( this->memDC.GetPixel( w , h ) != color )
  55. {
  56. r.CreateRectRgn( w , h , w + 1 , h + 1 );
  57. this->rgn.CombineRgn( &this->rgn , &r , RGN_OR );
  58. r.DeleteObject( );
  59. }
  60.    if( this->memDC.GetSafeHdc( ) )
  61.    this->memDC.DeleteDC( );
  62.    if( this->bitmap.GetSafeHandle( ) )
  63.    this->bitmap.DeleteObject( );
  64. }
  65. void CWBPen::MouseMove( UINT nFlags , CPoint point )
  66. {
  67. if( nFlags & MK_LBUTTON )
  68. {
  69. if( this->start.x > point.x ) this->start.x = point.x;
  70. if( this->start.y > point.y ) this->start.y = point.y;
  71. if( this->end.x < point.x ) this->end.x = point.x;
  72. if( this->end.y < point.y ) this->end.y = point.y;
  73. this->memDC.SelectObject( &this->pen );
  74. this->memDC.LineTo( point );
  75. this->view->GetMemDC( )->SelectObject( &this->pen );
  76. this->view->GetMemDC( )->LineTo( point );
  77. this->view->Invalidate( );
  78. }
  79. }
  80. CDC * CWBPen::Draw( CDC * pDC )
  81. {
  82. pDC = CDraw::Draw( pDC );
  83. return pDC;
  84. }