DrawView.cpp
资源名称:视频会议系统.rar [点击查看]
上传用户:popouu88
上传日期:2013-02-11
资源大小:2894k
文件大小:23k
源码类别:
IP电话/视频会议
开发平台:
Visual C++
- // DrawView.cpp : implementation file
- //
- #include "stdafx.h"
- #include "WB.h"
- #include "MainFrame.h"
- #include "DrawView.h"
- #include "DrawLine.h"
- #include "DrawRectangle.h"
- #include "DrawCircle.h"
- #include "DrawRoundRect.h"
- #include "DrawSelectDraw.h"
- #include "DrawWBPen.h"
- #include "Drawtext.h"
- #include "DrawWBWnd.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView
- CDrawView::CDrawView( CMainFrame * mainFrame )
- {
- this->mainFrame = mainFrame;
- this->iterator = NULL;
- this->curDraw = 0;
- this->draw = NULL;
- this->OnWB = NULL;
- this->pContext = NULL;
- this->userName = "";
- }
- CDrawView::~CDrawView()
- {
- CDraw * d = NULL;
- while( ! this->drawList.empty( ) )
- {
- d = this->drawList.front( );
- this->drawList.pop_front( );
- delete d;
- }
- if( this->draw )
- delete this->draw;
- if( this->iterator )
- delete this->iterator;
- }
- BEGIN_MESSAGE_MAP(CDrawView, CScrollView)
- //{{AFX_MSG_MAP(CDrawView)
- ON_WM_LBUTTONDOWN()
- ON_WM_LBUTTONUP()
- ON_WM_MOUSEMOVE()
- ON_WM_CREATE()
- ON_WM_VSCROLL()
- ON_WM_HSCROLL()
- ON_WM_ERASEBKGND()
- ON_BN_CLICKED(IDC_OPEN, OnOpen)
- ON_BN_CLICKED(IDC_SAVE, OnSave)
- ON_WM_CONTEXTMENU()
- ON_COMMAND(ID_DRAW_FIRST, OnDrawFirst)
- ON_COMMAND(ID_DRAW_LAST, OnDrawLast)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CDrawView drawing
- int CDrawView::OnCreate(LPCREATESTRUCT lpCreateStruct)
- {
- if (CScrollView::OnCreate(lpCreateStruct) == -1)
- return -1;
- //设定工作区大小
- this->SetScrollSizes( MM_TEXT , CSize( 2034 , 2034 ) );
- //指示器
- this->iterator = new CIterator( this );
- CClientDC dc( this );
- //取出工作区大小
- CSize s = this->GetTotalSize( );
- //设定内存画布
- this->memDC.CreateCompatibleDC( &dc );
- //设定内存位图
- this->memBitmap.CreateCompatibleBitmap( &dc , s.cx , s.cy );
- this->memDC.SelectObject( &this->memBitmap );
- //画布背景为白色
- this->memDC.FillSolidRect( 0 , 0 , s.cx , s.cy , this->memDC.GetBkColor( ) );
- // ::ScrollBar( this->GetSafeHwnd( ) );
- return 0;
- }
- BOOL CDrawView::OnEraseBkgnd(CDC* pDC)
- {
- return true;
- }
- //画图
- void CDrawView::OnDraw( CDC * pDC )
- {
- if( this->memDC.GetSafeHdc( ) && this->memBitmap.GetSafeHandle( ) )
- {
- CRect rc;
- this->GetClientRect( &rc );
- rc.OffsetRect( this->GetScrollPosition( ) );
- //显示内存位图
- pDC->BitBlt( rc.left , rc.top , rc.Width( ) , rc.Height( ) , &this->memDC , rc.left , rc.top , SRCCOPY );
- //显示远程指示器
- if( this->iterator )
- this->iterator->Draw( pDC );
- }
- }
- //刷新
- void CDrawView::Reflush( void )
- {
- if( this->memDC.GetSafeHdc( ) )
- { //取出工作区大小
- CSize s = this->GetTotalSize( );
- //画布背景为白色
- this->memDC.FillSolidRect( 0 , 0 , s.cx , s.cy , this->memDC.GetBkColor( ) );
- for( DRAW_LIST::iterator itr = this->drawList.begin( ); itr != this->drawList.end( ); itr ++ )
- ( * itr )->Draw( &this->memDC );
- this->Invalidate( );
- }
- }
- //组合数据
- void CDrawView::assembleData( CDraw * draw , ACTION action , int pos )
- {
- if( draw && this->OnWB )
- {
- char * buffer = NULL;
- int size = 0;
- int rgnSize = draw->GetRgn( ).GetRegionData( NULL , 0 );
- char * rgnData = new char[ rgnSize ];
- if( ! rgnData ) return;
- //取得区域
- draw->GetRgn( ).GetRegionData( ( RGNDATA * )rgnData , rgnSize );
- //用户名
- if( draw->userName.IsEmpty( ) ) draw->userName = this->userName;
- //用户名大小
- size += draw->userName.GetLength( ) + sizeof( char );
- //id
- size += sizeof( int );
- //图元类型
- size += sizeof( int );
- //图元操作
- size += sizeof( int );
- switch( action )
- {
- case ADD : //增加
- { //图元的类型
- size += sizeof( int );
- //区域的大小
- size += rgnSize;
- //区域颜色
- size += sizeof( int );
- char * bmBuffer = NULL;
- int bmSize = 0;
- //文本
- if( draw->GetType( ) == CDraw::TEXT )
- {
- size += ( ( CText * )draw )->GetText( ).GetLength( ) + sizeof( char );
- }//窗口
- else if( draw->GetType( ) == CDraw::WBWND || draw->GetType( ) == CDraw::WBWND1 )
- {
- CBitmap * bmp = ( ( CWBWnd * )draw )->GetBitmap( );
- BITMAP bm;
- bmp->GetBitmap( &bm );
- //设定位图无关信息
- BITMAPINFOHEADER h =
- {
- sizeof( h ) , bm.bmWidth , bm.bmHeight , 1 , bm.bmBitsPixel * bm.bmPlanes , BI_RGB , ( 31 + h.biWidth * h.biHeight * h.biBitCount ) / 8 , 0 , 0 , 0 , 0
- };
- bmSize = sizeof( h ) + h.biSizeImage;
- bmBuffer = new char[ 2 * bmSize ];
- //位图头信息
- memcpy( bmBuffer , &h , sizeof( h ) );
- //取出位图
- ::GetDIBits( this->memDC.GetSafeHdc( ) , * bmp , 0 , bm.bmHeight , bmBuffer + sizeof( h ) , ( BITMAPINFO * )&h , DIB_RGB_COLORS );
- size += bmSize;
- }//申请内存
- buffer = new char[ size ];
- if( ! buffer ) return;
- char * now = buffer;
- //用户名
- strcpy( now , draw->userName ); now += draw->userName.GetLength( ) + sizeof( char );
- //id
- *( int * )now = draw->drawId; now += sizeof( int );
- //图元类型
- *( int * )now = draw->GetType( ); now += sizeof( int );
- //图元操作
- *( int * )now = action; now += sizeof( int );
- //区域大小
- *( int * )now = rgnSize; now += sizeof( int );
- //区域
- memcpy( now , rgnData , rgnSize ); now += rgnSize;
- //区域颜色
- *( int * )now = draw->GetColor( ); now += sizeof( int );
- if( draw->GetType( ) == CDraw::TEXT )
- {
- strcpy( now , ( ( CText * )draw )->GetText( ) ); now += ( ( CText * )draw )->GetText( ).GetLength( ) + sizeof( char );
- }
- else if( draw->GetType( ) == CDraw::WBWND || draw->GetType( ) == CDraw::WBWND1 )
- memcpy( now , bmBuffer , bmSize );
- //通知外部程序
- this->OnWB( this->pContext , this->GetParent( ) , buffer , size );
- delete []buffer; buffer = NULL;
- if( bmBuffer )
- {
- delete []bmBuffer; bmBuffer = NULL;
- }
- }
- break;
- case DEL : //删除
- {
- buffer = new char[ size ];
- if( ! buffer ) return;
- char * now = buffer;
- //用户名
- strcpy( now , draw->userName ); now += draw->userName.GetLength( ) + sizeof( char );
- //id
- *( int * )now = draw->drawId; now += sizeof( int );
- //图元类型
- *( int * )now = draw->GetType( ); now += sizeof( int );
- //图元操作
- *( int * )now = action; now += sizeof( int );
- //通知外部程序
- this->OnWB( this->pContext , this->GetParent( ) , buffer , size );
- delete buffer; buffer = NULL;
- }
- break;
- case MODIFY : //修改
- { //图元的位置和颜色
- size += 3 * sizeof( int );
- buffer = new char[ size ];
- if( ! buffer ) return;
- char * now = buffer;
- //用户名
- strcpy( now , draw->userName ); now += draw->userName.GetLength( ) + sizeof( char );
- //id
- *( int * )now = draw->drawId; now += sizeof( int );
- //图元类型
- *( int * )now = draw->GetType( ); now += sizeof( int );
- //图元操作
- *( int * )now = action; now += sizeof( int );
- //图元所在的位置
- CRect rc;
- draw->GetRgn( ).GetRgnBox( &rc );
- *( int * )now = rc.left; now += sizeof( int );
- *( int * )now = rc.top; now += sizeof( int );
- //图元的颜色
- *( int * )now = draw->GetColor( );
- //通知外部程序
- this->OnWB( this->pContext , this->GetParent( ) , buffer , size );
- delete buffer;buffer = NULL;
- }
- break;
- case POSITION :
- {
- size += sizeof( int );
- buffer = new char[ size ];
- if( ! buffer ) return;
- char * now = buffer;
- //用户名
- strcpy( now , draw->userName ); now += draw->userName.GetLength( ) + sizeof( char );
- //id
- *( int * )now = draw->drawId; now += sizeof( int );
- //图元类型
- *( int * )now = draw->GetType( ); now += sizeof( int );
- //图元操作
- *( int * )now = action; now += sizeof( int );
- //前还是后
- *( int * )now = pos; // 1 表示前 ; 2 表示后
- //通知外部程序
- this->OnWB( this->pContext , this->GetParent( ) , buffer , size );
- delete buffer; buffer = NULL;
- }break;
- }
- delete rgnData; rgnData = NULL;
- }
- }
- //解析数据
- void CDrawView::parseData( char * buffer , int size )
- { //用户名
- CString username = buffer; buffer += username.GetLength( ) + sizeof( char );
- //draw id
- int drawid = *( int * )buffer; buffer += sizeof( int );
- //图元类型
- int type = *( int * )buffer ; buffer += sizeof( int );
- //图元的行为
- ACTION action = * ( ACTION * )buffer ; buffer += sizeof( int );
- CDraw * draw = NULL;
- //增加一个图元
- if( action == ADD )
- { //区域大小
- int rgnSize = *( int * )buffer; buffer += sizeof( int );
- char * rgnData = buffer; buffer += rgnSize;
- switch( type )
- {
- case CDraw::LINE : draw = new CLine( this ); break;
- case CDraw::RECT : draw = new CRectangle( this ); break;
- case CDraw::CIRCLE : draw = new CCircle( this ); break;
- case CDraw::ROUNDRECT : draw = new CRoundRect( this );break;
- case CDraw::PEN :
- case CDraw::PEN1 : draw = new CWBPen( this ); break;
- case CDraw::TEXT : draw = new CText( this ); break;
- case CDraw::WBWND :
- case CDraw::WBWND1 :
- draw = new CWBWnd( this , false , false ); break;
- }
- if( draw )
- {
- draw->userName = username;
- draw->drawId = drawid;
- //创建区域
- draw->GetRgn( ).CreateFromData( NULL , rgnSize , ( RGNDATA * )rgnData );
- //颜色
- draw->SetColor( *( int * )buffer ); buffer += sizeof( int );
- //文本
- if( draw->GetType( ) == CDraw::TEXT )
- ( ( CText * )draw )->SetText( buffer );
- //窗口
- else if( draw->GetType( ) == CDraw::WBWND || draw->GetType( ) == CDraw::WBWND )
- {
- CBitmap * bmp = ( ( CWBWnd * )draw )->GetBitmap( );
- if( ! bmp )
- {
- delete draw; return;
- }
- BITMAPINFOHEADER * h = ( BITMAPINFOHEADER * )buffer; buffer += sizeof( BITMAPINFOHEADER );
- ::SetDIBits( this->memDC.GetSafeHdc( ) , * bmp , 0 , h->biHeight , buffer , ( BITMAPINFO * )h , DIB_RGB_COLORS );
- }
- this->drawList.push_back( draw );
- }
- }
- else if( action == MODIFY )
- {
- this->LockList( );
- //查找图元
- for( DRAW_LIST::iterator itr = this->drawList.begin( ); itr != this->drawList.end( ); itr ++ )
- {
- draw = * itr;
- if( draw->userName == username && draw->drawId == drawid )
- {
- CRect rc;
- draw->GetRgn( ).GetRgnBox( &rc );
- draw->GetRgn( ).OffsetRgn( - rc.left , - rc.top );
- rc.left = *( int * )buffer; buffer += sizeof( int );
- rc.top = *( int * )buffer; buffer += sizeof( int );
- draw->GetRgn( ).OffsetRgn( rc.left , rc.top );
- draw->SetColor( *( int * )buffer );
- break;
- }
- }
- this->UnlockList( );
- }
- else if( action == DEL )
- { //查找图元
- this->LockList( );
- for( DRAW_LIST::iterator itr = this->drawList.begin( ); itr != this->drawList.end( ); itr ++ )
- {
- draw = * itr;
- if( draw->userName == username && draw->drawId == drawid )
- {
- this->drawList.erase( itr );
- break;
- }
- }
- this->UnlockList( );
- }//指示器
- else if( action == ITERATOR )
- { //是否显示
- bool m_bShow = *( int * )buffer; buffer += sizeof( int );
- //坐标
- CPoint point;
- point.x = *( int * )buffer; buffer += sizeof( int );
- point.y = *( int * )buffer;
- this->GetIterator( )->SetIterator( &m_bShow , &point );
- if( this->mainFrame )
- ( ( CButton * )this->mainFrame->GetToolBar( ).GetDlgItem( IDC_RADIO12 ) )->SetCheck( m_bShow );
- }
- else if( action == POSITION )
- { //1表示前 2 表示后
- int pos = *( int * )buffer;
- //查找图元
- this->LockList( );
- for( DRAW_LIST::iterator itr = this->drawList.begin( ); itr != this->drawList.end( ); itr ++ )
- {
- draw = * itr;
- //找到了
- if( draw->userName == username && draw->drawId == drawid )
- {
- this->drawList.remove( draw );
- if( pos == 1 )
- this->drawList.push_back( draw );
- else if( pos == 2 )
- this->drawList.push_front( draw );
- break;
- }
- }
- this->UnlockList( );
- }
- this->Reflush( );
- }
- //选择工具
- void CDrawView::SelectDraw( int index , COLORREF color , int width , bool m_bEmpty )
- {
- this->curDraw = index;
- if( this->draw )
- {
- if( this->draw->GetType( ) == CDraw::TEXT )
- {
- CText * text = ( CText * )this->draw;
- //保存
- if( ! text->GetText( ).IsEmpty( ) )
- {
- if( ! text->GetRgn( ).GetSafeHandle( ) )
- text->LButtonUp( 0 , CPoint( 0 , 0 ) );
- this->drawList.push_back( this->draw );
- }
- else
- {
- delete this->draw; this->draw = NULL;
- }
- }
- else //删除
- {
- delete this->draw; this->draw = NULL;
- }
- }
- switch( index )
- {
- case CDraw::SELECT : this->draw = new CSelectDraw( this ); break;
- case CDraw::LINE : this->draw = new CLine( this ); break;
- case CDraw::RECT : this->draw = new CRectangle( this ); break;
- case CDraw::CIRCLE : this->draw = new CCircle( this ); break;
- case CDraw::ROUNDRECT : this->draw = new CRoundRect( this ); break;
- case CDraw::PEN : this->draw = new CWBPen( this , 0 ); break;
- case CDraw::PEN1 : this->draw = new CWBPen( this , 1 ); break;
- case CDraw::TEXT : this->draw = new CText( this ); break;
- case CDraw::WBWND : this->draw = new CWBWnd( this , true ); break;
- case CDraw::WBWND1 : this->draw = new CWBWnd( this , false ); break;
- }
- if( this->draw )
- {
- if( this->draw->GetType( ) == CDraw::PEN1 )
- {
- this->draw->SetColor( RGB( 255 , 255 , 0 ) );
- //设定宽度
- this->draw->SetWidth( 2 );
- //设定内部空区是否为空
- this->draw->SetEmpty( m_bEmpty );
- }
- else
- { //设定颜色
- this->draw->SetColor( color );
- //设定宽度
- this->draw->SetWidth( width );
- //设定内部空区是否为空
- this->draw->SetEmpty( m_bEmpty );
- }
- }
- }
- //鼠标下压
- void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
- {
- CScrollView::OnLButtonDown( nFlags, point );
- point.Offset( this->GetScrollPosition( ) );
- if( this->iterator->LButtonDown( nFlags , point ) )
- return;
- if( this->draw )
- {
- if( this->draw->GetType( ) != CDraw::WBWND )
- {
- CRect rc;
- this->GetClientRect( &rc );
- this->ClientToScreen( &rc );
- ::ClipCursor( &rc );
- }
- this->draw->LButtonDown( nFlags , point );
- }
- }
- //鼠标弹起
- void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
- {
- CScrollView::OnLButtonUp(nFlags, point);
- point.Offset( this->GetScrollPosition( ) );
- if( this->iterator->LButtonUp( nFlags , point ) )
- return;
- ::ClipCursor( NULL );
- if( this->draw )
- {
- this->draw->LButtonUp( nFlags , point );
- int type = this->draw->GetType( );
- if( type != CDraw::SELECT )
- { //保存
- this->drawList.push_back( this->draw );
- //通知外部程序增加一个图元
- this->assembleData( draw , ADD );
- //取出颜色
- COLORREF color = this->draw->GetColor( );
- //取出宽度
- int width = this->draw->GetWidth( );
- //取出是否为空
- bool empty = this->draw->IsEmpty( );
- //再次实例化
- this->draw = NULL;
- // this->Reflush( );
- if( type == CDraw::WBWND || type == CDraw::WBWND1 )
- type = CDraw::SELECT;
- this->SelectDraw( type , color , width , empty );
- }
- }
- }
- //鼠标移动
- void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
- {
- CScrollView::OnMouseMove( nFlags, point);
- point.Offset( this->GetScrollPosition( ) );
- if( this->iterator->MouseMove( nFlags , point ) )
- return;
- if( this->draw )
- this->draw->MouseMove( nFlags , point );
- }
- void CDrawView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- CScrollView::OnVScroll(nSBCode, nPos, pScrollBar);
- this->Invalidate( );
- }
- void CDrawView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
- {
- CScrollView::OnHScroll(nSBCode, nPos, pScrollBar);
- this->Invalidate( );
- }
- void CDrawView::OnOpen()
- {
- CFileDialog dlg( true , "*.wb|*.bmp|" , NULL , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , "白板文件( *.wb)|*.wb|位图文件( *.bmp )|*.bmp||");
- if( dlg.DoModal( ) == IDOK )
- {
- CFile file;
- if( file.Open( dlg.GetPathName( ) , CFile::modeRead ) )
- {
- int size = file.GetLength( );
- char * buffer = new char[ size ];
- file.Read( buffer , size );
- file.Close( );
- char * now = buffer;
- //白板文件
- if( ! dlg.GetFileExt( ).CompareNoCase( "wb" ) )
- {//图元类型 + 图元区域 + 图元的参数
- CDraw * draw = NULL;
- int rgnSize = 0;
- char * rgnData = NULL;
- while( now < buffer + size )
- {
- draw = NULL;
- //类型
- switch( *( int * )now )
- {
- case CDraw::LINE : draw = new CLine( this ); break;
- case CDraw::RECT : draw = new CRectangle( this ); break;
- case CDraw::CIRCLE : draw = new CCircle( this ); break;
- case CDraw::ROUNDRECT : draw = new CRoundRect( this );break;
- case CDraw::PEN :
- case CDraw::PEN1 : draw = new CWBPen( this ); break;
- case CDraw::TEXT : draw = new CText( this ); break;
- case CDraw::WBWND :
- case CDraw::WBWND1 :
- draw = new CWBWnd( this , false , false ); break;
- }
- now += sizeof( int );
- //区域
- if( draw )
- draw->GetRgn( ).CreateFromData( NULL , *( int * )now , ( RGNDATA * )( now + sizeof( int ) ) );
- now += sizeof( int ) + *( int * )now;
- //颜色
- if( draw )
- draw->SetColor( *( int * )now );
- now += sizeof( int );
- //如果是文本
- if( draw->GetType( ) == CDraw::TEXT )
- {
- ( ( CText * )draw )->SetText( now ); now += strlen( now ) + sizeof( char );
- }//如果是位图
- if( draw->GetType( ) == CDraw::WBWND || draw->GetType( ) == CDraw::WBWND1 )
- {
- CBitmap * bmp = ( ( CWBWnd * )draw )->GetBitmap( );
- BITMAPINFOHEADER * h = ( BITMAPINFOHEADER * )now; now += sizeof( BITMAPINFOHEADER );
- ::SetDIBits( this->memDC.GetSafeHdc( ) , * bmp , 0 , h->biHeight , now , ( BITMAPINFO * )h , DIB_RGB_COLORS );
- now += h->biSizeImage;
- }
- if( draw )
- {
- draw->Draw( );
- this->assembleData( draw , ADD );
- this->drawList.push_back( draw );
- }
- }
- this->Invalidate( );
- }//位图文件
- else if( ! dlg.GetFileExt( ).CompareNoCase( "bmp" ) )
- {
- CWBWnd * draw = new CWBWnd( this , false , false );
- BITMAPINFOHEADER * h = ( BITMAPINFOHEADER * )now; now += sizeof( BITMAPINFOHEADER );
- draw->GetRgn( ).CreateRectRgn( 0 , 0 , h->biWidth , h->biHeight );
- ::SetDIBits( this->memDC.GetSafeHdc( ) , * draw->GetBitmap( ) , 0 , h->biHeight , now , ( BITMAPINFO * )h , DIB_RGB_COLORS );
- now += h->biSizeImage;
- draw->Draw( );
- this->assembleData( draw , ADD );
- this->drawList.push_back( draw );
- }
- delete []buffer;
- }
- }
- }
- void CDrawView::OnSave()
- {
- CFileDialog dlg( false , "*.wb|*.bmp|" , NULL , OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT , "白板文件( *.wb)|*.wb|位图文件( *.bmp )|*.bmp||");
- if( dlg.DoModal( ) == IDOK )
- { //白板文件
- if( ! dlg.GetFileExt( ).CompareNoCase( "wb" ) )
- {// 图元类型 + 图元区域 + 图元的参数
- CFile file;
- if( file.Open( dlg.GetPathName( ) , CFile::modeCreate | CFile::modeWrite ) )
- {
- this->LockList( );
- CDraw * draw = NULL;
- int rgnSize = 0;
- char * rgnData = NULL;
- for( DRAW_LIST::iterator itr = this->drawList.begin( ); itr != this->drawList.end( ); itr ++ )
- {
- draw = * itr;
- //类型
- rgnSize = draw->GetType( );
- file.Write( &rgnSize , sizeof( int ) );
- //区域大小
- rgnSize = draw->GetRgn( ).GetRegionData( NULL , 0 );
- file.Write( &rgnSize , sizeof( int ) );
- rgnData = new char[ rgnSize ];
- //区域
- draw->GetRgn( ).GetRegionData( ( RGNDATA * )rgnData , rgnSize );
- file.Write( rgnData , rgnSize );
- delete []rgnData;
- //颜色
- rgnSize = draw->GetColor( );
- file.Write( &rgnSize , sizeof( int ) );
- //文本格式
- if( draw->GetType( ) == CDraw::TEXT )
- {
- CText * text = ( CText * )draw;
- file.Write( text->GetText( ) , text->GetText( ).GetLength( ) + sizeof( char ) );
- }
- if( draw->GetType( ) == CDraw::WBWND || draw->GetType( ) == CDraw::WBWND1 )
- {
- CBitmap * bmp = ( ( CWBWnd * )draw )->GetBitmap( );
- BITMAP bm;
- bmp->GetBitmap( &bm );
- //设定位图无关信息
- BITMAPINFOHEADER h =
- {
- sizeof( h ) , bm.bmWidth , bm.bmHeight , 1 , bm.bmBitsPixel * bm.bmPlanes , BI_RGB , ( 31 + h.biWidth * h.biHeight * h.biBitCount ) / 8 , 0 , 0 , 0 , 0
- };
- rgnData = new char[ h.biSizeImage * 2 ];
- //位图头信息
- file.Write( &h , sizeof( h ) );
- //取出位图
- ::GetDIBits( this->memDC.GetSafeHdc( ) , * bmp , 0 , bm.bmHeight , rgnData , ( BITMAPINFO * )&h , DIB_RGB_COLORS );
- file.Write( rgnData , h.biSizeImage );
- delete [ ]rgnData;
- }
- }
- this->UnlockList( );
- file.Close( );
- }
- }//位图文件
- else if( ! dlg.GetFileExt( ).CompareNoCase( "bmp" ) )
- {
- BITMAP bm;
- this->memBitmap.GetBitmap( &bm );
- BITMAPINFOHEADER h =
- {
- sizeof( h ) , bm.bmWidth , bm.bmHeight , 1 , bm.bmBitsPixel * bm.bmPlanes , BI_RGB , ( 31 + h.biWidth * h.biHeight * h.biBitCount ) / 8 , 0 , 0 , 0 , 0
- };
- char * buffer = new char[ h.biSizeImage ];
- ::GetDIBits( this->memDC.GetSafeHdc( ) , this->memBitmap , 0 , h.biHeight , buffer , ( BITMAPINFO * )&h , DIB_RGB_COLORS );
- CFile file;
- if( file.Open( dlg.GetPathName( ) , CFile::modeCreate | CFile::modeWrite ) )
- {
- file.Write( &h , sizeof( h ) );
- file.Write( buffer , h.biSizeImage );
- file.Close( );
- }
- delete []buffer;
- }
- }
- }
- void CDrawView::OnContextMenu(CWnd* pWnd, CPoint point)
- {
- CSelectDraw * sd = ( CSelectDraw * )this->draw;
- if( sd->GetType( ) == CDraw::SELECT )
- {
- CMenu menu , * m ;
- menu.LoadMenu( IDR_DRAW_MENU );
- m = menu.GetSubMenu( 0 );
- if( sd->GetList( )->size( ) == 1 && this->drawList.size( ) > 1 )
- {
- m->EnableMenuItem( 0 , MF_ENABLED | MF_BYPOSITION );
- m->EnableMenuItem( 1 , MF_ENABLED | MF_BYPOSITION );
- }
- m->TrackPopupMenu( TPM_LEFTALIGN , point.x , point.y , this );
- }
- }
- void CDrawView::OnDrawFirst()
- {
- CSelectDraw * sd = ( CSelectDraw * )this->draw;
- try
- {
- CDraw * draw = * sd->GetList( )->begin( );
- this->drawList.remove( draw );
- this->drawList.push_back( draw );
- this->Reflush( );
- this->assembleData( draw , POSITION , 1 );
- }
- catch( ... )
- {
- }
- }
- void CDrawView::OnDrawLast()
- {
- CSelectDraw * sd = ( CSelectDraw * )this->draw;
- try
- {
- CDraw * draw = * sd->GetList( )->begin( );
- this->drawList.remove( draw );
- this->drawList.push_front( draw );
- this->Reflush( );
- this->assembleData( draw , POSITION , 2 );
- }
- catch( ... )
- {
- }
- }