📄 drawview.cpp
字号:
//数据
char * buf;
for( DRAW_MAP::iterator itr = this->GetDrawMap().begin(); itr != this->GetDrawMap().end(); itr ++ )
{
buf = itr->second->Encode( size );
if( buf )
{ //数据大小
file.Write( &size , sizeof( int ) );
//数据
file.Write( buf , size );
//删除数据
delete []buf;
}
}
}
// else if( this->memBMP.GetSafeHandle() )
// {
// BITMAP bm;
//
// this->memBMP.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
// };
// BITMAPFILEHEADER fh =
// {
// 0x4d42 , sizeof( fh ) + sizeof( h ) + h.biSizeImage , 0 , 0 , sizeof( h )
// };
// char * buffer = new char[ h.biSizeImage ];
//
// ::GetDIBits( this->memDC.GetSafeHdc( ) , this->memBMP , 0 , h.biHeight , buffer , ( BITMAPINFO * )&h , DIB_RGB_COLORS );
// //位图头文件
// file.Write( &fh , sizeof( fh ) );
// //位图头信息
// file.Write( &h , sizeof( h ) );
// //位图数据
// file.Write( buffer , h.biSizeImage );
//
// delete []buffer;
// }
file.Close();
}
}
}
void CDrawView::OnColor()
{
int color = 0;
if( ! this->GetCurrentMessage()->lParam )
{
CColorDialog dlg;
if( dlg.DoModal() != IDOK )
return;
color = dlg.GetColor();
}
else
color = this->GetFrame().GetBar().GetColorCombo().GetSelectedValue();
this->draw->GetProp().pen.lopnColor = this->draw->GetProp().brush.lbColor = color;
for( DRAW_MAP::iterator itr = this->GetDrawMap().begin(); itr != this->GetDrawMap().end(); itr ++ )
if( itr->second->IsSelect() )
{
itr->second->GetProp().pen.lopnColor = color;
itr->second->GetProp().brush.lbColor = color;
}
//组合数据往网络发送
if( IsDescendant( this->draw , CSelect ) )
this->Assemble( this->draw );
this->Invalidate();
}
void CDrawView::OnTool( UINT id )
{
static int item = ID_DRAW_LINE;
if( item )
{
this->menu.CheckMenuItem( item | MF_BYCOMMAND , MF_UNCHECKED );
if( this->GetFrame().GetBar().GetToolBarCtrl() )
this->GetFrame().GetBar().GetToolBarCtrl().CheckButton( item , FALSE );
}
item = id;
this->menu.CheckMenuItem( item | MF_BYCOMMAND , MF_CHECKED );
if( this->GetFrame().GetBar().GetToolBarCtrl() )
this->GetFrame().GetBar().GetToolBarCtrl().CheckButton( item , TRUE );
switch( id )
{
case ID_DRAW_LINE : SELECT_DRAW( CLine , false ); break;
case ID_DRAW_PEN : SELECT_DRAW( CWBPen , false ); break;
case ID_DRAW_EMPTYRECT : SELECT_DRAW( CRectangle , true ); break;
case ID_DRAW_SOLIDRECT : SELECT_DRAW( CRectangle , false ); break;
case ID_DRAW_EMPTYROUNDRECT : SELECT_DRAW( CRoundRect , true );break;
case ID_DRAW_SOLIDROUNDRECT : SELECT_DRAW( CRoundRect , false ); break;
case ID_DRAW_EMPTYCIRCLE : SELECT_DRAW( CCircle , true ); break;
case ID_DRAW_SOLIDCIRCLE : SELECT_DRAW( CCircle , false ); break;
case ID_DRAW_FONT : SELECT_DRAW( CText , false ); break;
case ID_DRAW_SELECT : SELECT_DRAW( CSelect , false ); break;
case ID_DRAW_DELETE : SELECT_DRAW( CSelect , true ); break;
}
}
BOOL CDrawView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{ //更改鼠标形状
if( this->draw && nHitTest == HTCLIENT )
{
::SetCursor( this->draw->GetCursor() );
return TRUE;
}
return CScrollView::OnSetCursor(pWnd, nHitTest, message);
}
void CDrawView::OnLine( UINT id )
{
int line;
if( ! this->GetCurrentMessage()->lParam )
{
static int item = ID_LINE_1_PIXEL;
if( item ) this->menu.CheckMenuItem( item | MF_BYCOMMAND , MF_UNCHECKED );
item = id;
this->menu.CheckMenuItem( item | MF_BYCOMMAND , MF_CHECKED );
line = id - ID_LINE_1_PIXEL + 1;
}
else
line = this->GetFrame().GetBar().GetLineTypeCombo().GetSelectedValue();
this->draw->GetProp().pen.lopnWidth = CPoint( line , line );
for( DRAW_MAP::iterator itr = this->GetDrawMap().begin(); itr != this->GetDrawMap().end(); itr ++ )
if( itr->second->IsSelect() )
itr->second->GetProp().pen.lopnWidth = CPoint( line , line );
//组合数据往网络发送
if( IsDescendant( this->draw , CSelect ) )
this->Assemble( this->draw );
//刷新
this->Invalidate();
}
//组合数据
bool CDrawView::Assemble( CDrawBase * draw )
{
int size;
char * buffer = draw->Encode( size );
if( buffer )
::PostThreadMessage( this->send_threadid , WM_THREAD_SEND , ( WPARAM )buffer , ( LPARAM )size );
return ! IsDescendant( draw , CSelect );
}
//发送线程
DWORD WINAPI CDrawView::OnSend( void * pContext )
{
CDrawView * pThis = ( CDrawView * )pContext;
MSG msg;
char * buffer;
while( ::GetMessage( &msg , NULL , 0 , 0 ) )
{ //通过消息获得要发送的数据包
if( msg.message == WM_THREAD_SEND )
{
buffer = ( char * )msg.wParam;
if( buffer )
{
if( pThis->OnWB )
pThis->OnWB( pThis->pContext , pThis->GetParent()->GetSafeHwnd() , buffer , msg.lParam );
//清除Post过来的数据
delete []buffer;
}
}
}
return 0;
}
void CDrawView::OnParse( WPARAM wParam , LPARAM lParam )
{
char * buffer = ( char * )wParam;
int size = lParam;
CString id = buffer;
//the id of CSelect Object is Empty
if( id.IsEmpty() )
{
CSelect s( * this );
s.Decode( buffer , size );
}//Add a new Object
else if( this->GetDrawMap().find( id ) == this->GetDrawMap().end() )
{
CDrawBase * d = NULL;
DRAW draw;
memcpy( &draw , buffer + id.GetLength() + 1 , sizeof( DRAW ) );
switch( draw.tag )
{
case CDrawBase::LINE : d = new CLine( * this ); break;
case CDrawBase::PEN : d = new CWBPen( * this ); break;
case CDrawBase::RECT : d = new CRectangle( * this ); break;
case CDrawBase::ROUNDRECT : d = new CRoundRect( * this ); break;
case CDrawBase::CIRCLE : d = new CCircle( * this ); break;
case CDrawBase::TEXT : d = new CText( * this ); break;
}
if( d )
{
if( d->Decode( buffer , size ) )
this->GetDrawMap()[ d->GetId() ] = d;
else
delete d;
}
}//清除Post过来的数据
delete []buffer;
//刷新
this->Invalidate();
}
void CDrawView::OnScrollButton( UINT id )
{
switch( id - FIRST_SCROLL_BUTTON )
{
case 0 : this->page = this->page > 1 ? this->page - 1 : 1; break;
case 1 : this->page ++; break;
case 2 : break;
}
this->Invalidate();
if( this->draw )
this->draw->GetProp().page = this->page;
}
BOOL CDrawView::OnScrollNotify( NMCSBCUSTOMDRAW *nm , LRESULT* result )
{
if( nm->nBar == SB_INSBUT )
{
* result = CDRF_SKIPDEFAULT;
CDC * pDC = CDC::FromHandle( nm->hdc );
pDC->SetTextColor( RGB( 0 , 0 , 0 ) );
pDC->SetBkMode( TRANSPARENT );
CBrush nb( ::GetSysColor( COLOR_BTNFACE ) );
pDC->SelectObject( & nb );
int width = pDC->GetTextExtent( "00" ).cx + 6;
//判断该长度能够显示多少个数字
int number = ( nm->rect.right - nm->rect.left ) / width - 3;
//起始位置
number = this->page - number;
if( number < 1 ) number = 1;
else if( number > this->page ) number = this->page;
CString s;
CRect rc;
for( int i = nm->rect.left ; i < nm->rect.right ; i += width + 5 , number ++ )
{
if( number < 10 ) s.Format( "0%d", number );
else s.Format( "%d" , number );
rc.SetRect( i - 1 , nm->rect.top , i + width + 5 , nm->rect.bottom );
if( number == this->page )
{
pDC->FillSolidRect( &rc , RGB( 255 , 255 , 255 ) );
pDC->MoveTo( rc.left , rc.top ); pDC->LineTo( rc.left , rc.bottom );
pDC->MoveTo( rc.left , rc.bottom - 1 ); pDC->LineTo( rc.right , rc.bottom - 1 );
}
else
pDC->Rectangle( rc );
pDC->DrawText( s , &rc , DT_VCENTER | DT_CENTER );
}
}
return TRUE;
}
void CDrawView::OnDestroy()
{
if( this->send_threadid )
::PostThreadMessage( this->send_threadid , WM_QUIT , 0 , 0 );
CScrollView::OnDestroy();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -