WBPen.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:3k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // WBPen.cpp: implementation of the CWBPen class.
- //
- //////////////////////////////////////////////////////////////////////
- #include "stdafx.h"
- #include "..WB.h"
- #include "WBPen.h"
- #ifdef _DEBUG
- #undef THIS_FILE
- static char THIS_FILE[]=__FILE__;
- #define new DEBUG_NEW
- #endif
- #pragma comment( lib , "msimg32.lib" )
- //////////////////////////////////////////////////////////////////////
- // Construction/Destruction
- //////////////////////////////////////////////////////////////////////
- CWBPen::CWBPen( CDrawView * view , int ps ) : CDraw( view )
- {
- this->type = ! ps ? PEN : PEN1;
- CDC * pDC = this->view->GetMemDC( );
- this->memDC.CreateCompatibleDC( pDC );
- this->bitmap.CreateCompatibleBitmap( pDC , this->dcSize.cx , this->dcSize.cy );
- this->memDC.SelectObject( &this->bitmap );
- this->memDC.FillSolidRect( 0 , 0 , this->dcSize.cx , this->dcSize.cy , this->memDC.GetBkColor( ) );
- }
- CWBPen::~CWBPen()
- {
- }
- void CWBPen::LButtonDown( UINT nFlags , CPoint point )
- {
- CDraw::LButtonDown( nFlags , point );
- if( nFlags & MK_LBUTTON )
- {
- this->memDC.SelectObject( &this->pen );
- this->memDC.MoveTo( point );
- this->view->GetMemDC( )->MoveTo( point );
- this->start = this->end = point;
- }
- }
- void CWBPen::LButtonUp( UINT nFlags , CPoint point )
- {
- CWaitCursor cursor;
- int width = this->GetWidth( );
- this->start.Offset( - width , - width );
- this->end.Offset( width , width );
- CRect rc( this->start , this->end );
- rc.NormalizeRect( );
- if( this->rgn.GetSafeHandle( ) )
- this->rgn.DeleteObject( );
- this->rgn.CreateRectRgn( 0 , 0 , 0 , 0 );
- CRgn r;
- int color = this->memDC.GetBkColor( );
- for( int h = rc.top; h < rc.bottom; h ++ )
- for( int w = rc.left; w < rc.right; w ++ )
- if( this->memDC.GetPixel( w , h ) != color )
- {
- r.CreateRectRgn( w , h , w + 1 , h + 1 );
- this->rgn.CombineRgn( &this->rgn , &r , RGN_OR );
- r.DeleteObject( );
- }
- if( this->memDC.GetSafeHdc( ) )
- this->memDC.DeleteDC( );
- if( this->bitmap.GetSafeHandle( ) )
- this->bitmap.DeleteObject( );
- }
- void CWBPen::MouseMove( UINT nFlags , CPoint point )
- {
- if( nFlags & MK_LBUTTON )
- {
- if( this->start.x > point.x ) this->start.x = point.x;
- if( this->start.y > point.y ) this->start.y = point.y;
- if( this->end.x < point.x ) this->end.x = point.x;
- if( this->end.y < point.y ) this->end.y = point.y;
- this->memDC.SelectObject( &this->pen );
- this->memDC.LineTo( point );
- this->view->GetMemDC( )->SelectObject( &this->pen );
- this->view->GetMemDC( )->LineTo( point );
- this->view->Invalidate( );
- }
- }
- CDC * CWBPen::Draw( CDC * pDC )
- {
- pDC = CDraw::Draw( pDC );
- return pDC;
- }