学习VC++深入浅出——绘图操作

学习VC++深入浅出——绘图操作
public :
    COLORREF m_clr;
    CBrush m_brush;
    CBrush m_brush1;
    CFont m_font;

void  CGraphicView::OnDot() 
{
    
// TODO: Add your command handler code here
    m_iFlag = 1;
    
}


void  CGraphicView::OnElllipse() 
{
    
// TODO: Add your command handler code here
    m_iFlag = 4;
    
}


void  CGraphicView::OnLine() 
{
    
// TODO: Add your command handler code here
    m_iFlag = 2;
}


void  CGraphicView::OnRectangle() 
{
    
// TODO: Add your command handler code here
    m_iFlag = 3;
}


void  CGraphicView::OnSetting() 
{
    
// TODO: Add your command handler code here
    CSettingDlg dlg;
    dlg.m_nLineWidth 
= m_nLineWidth;
    dlg.m_nLineStyle 
= m_nLineStyle;
    dlg.m_clr 
=m_clr;
    
if(IDOK == dlg.DoModal())
    
{
        m_nLineWidth 
= dlg.m_nLineWidth;
        m_nLineStyle 
= dlg.m_nLineStyle;
    }

}


void  CGraphicView::OnLButtonDown(UINT nFlags, CPoint point) 
{
    
// TODO: Add your message handler code here and/or call default
    
    
if(m_iFlag == 1)
    
{
        CClientDC cdc(
this);
        cdc.SetPixel(point,m_clr);
    }

    
else
    
{
        oldPoint 
= point;
    }


//    CGraph *graph= new CGraph(m_nLineWidth,oldPoint,point);
//    m_ptrArray.Add(&graph);

    CScrollView::OnLButtonDown(nFlags, point);
}


void  CGraphicView::OnCancelMode() 
{
    CScrollView::OnCancelMode();
    
    
// TODO: Add your message handler code here
    
}


void  CGraphicView::OnLButtonUp(UINT nFlags, CPoint point) 
{
    
// TODO: Add your message handler code here and/or call default
    
    CClientDC cdc(
this);
    CPen
* oldPen;
    CPen pen(m_nLineStyle,m_nLineWidth,m_clr);
    oldPen 
= (CPen*)cdc.SelectObject(&pen);
    
if(m_iFlag == 2)
    
{
        cdc.MoveTo(oldPoint);
        cdc.LineTo(point);
    }

    
else if(m_iFlag == 3)
    
{
        CRect rect(oldPoint,point);
        cdc.Rectangle(rect);
    }

    
else if(m_iFlag == 4)
    
{
        CRect rect(oldPoint,point);
        cdc.Ellipse(rect);
    }

    cdc.SelectObject(oldPen);

    CGraph 
*graph = new CGraph(m_nLineWidth,oldPoint,point);
    m_ptrArray.Add(
&graph);

    CScrollView::OnLButtonUp(nFlags, point);
}


void  CGraphicView::OnCaptureChanged(CWnd  * pWnd) 
{
    
// TODO: Add your message handler code here
    
    CScrollView::OnCaptureChanged(pWnd);
}


void  CGraphicView::OnColor() 
{
    
// TODO: Add your command handler code here
    
    CColorDialog dlg;
//    CString str;
//    str.Format("%d",dlg.m_cc);
//    MessageBox(str);
    dlg.m_cc.Flags |= CC_RGBINIT | CC_FULLOPEN;
    dlg.m_cc.rgbResult 
= m_clr;
    
if(IDOK == dlg.DoModal())
    
{
        m_clr 
= dlg.m_cc.rgbResult;
    }


}


void  CGraphicView::OnFont() 
{
    
// TODO: Add your command handler code here
    CFontDialog dlg;
    
if(IDOK ==dlg.DoModal())
    
{
        
if(m_font.m_hObject)
        
{
            m_font.DeleteObject();
        }

        m_font.CreateFontIndirect(dlg.m_cf.lpLogFont);
        m_strFontName 
= dlg.m_cf.lpLogFont->lfFaceName;
        Invalidate();
    }

    
}


BOOL CGraphicView::OnEraseBkgnd(CDC
*  pDC) 
{
    
// TODO: Add your message handler code here and/or call default
    
    CBitmap bitmap;
    bitmap.LoadBitmap(IDB_BITMAP1);

    CDC dcCompatible;
    dcCompatible.CreateCompatibleDC(pDC);

    dcCompatible.SelectObject(
&bitmap);

    CRect rect;
    GetClientRect(
&rect);
//    pDC->BitBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,SRCCOPY);
    BITMAP bmp;
    bitmap.GetBitmap(
&bmp);
//    pDC->StretchBlt(0,0,rect.Width(),rect.Height(),&dcCompatible,0,0,bmp.bmWidth,bmp.bmHeight,SRCCOPY);
//    return true;
    return CScrollView::OnEraseBkgnd(pDC);
}


void  CGraphicView::OnInitialUpdate() 
{
    CScrollView::OnInitialUpdate();
    
    
// TODO: Add your specialized code here and/or call the base class
    SetScrollSizes(MM_TEXT,CSize(800,600));
}


void  CGraphicView::OnFileWrite() 
{
    
// TODO: Add your command handler code here
    CFile file("1.txt",CFile::modeCreate |CFile::modeWrite);
    CArchive ar(
&file,CArchive::store);
    
int i = 4;
    
char ch = 'a';
    
float f = 1.3f;
    CString str(
"http://www.zhangdali.org");
    ar
<<i<<ch<<f<<str;
}


void  CGraphicView::OnFileRead() 
{
    
// TODO: Add your command handler code here
    CFile file("1.txt",CFile::modeRead);
    CArchive ar(
&file,CArchive::load);
    
int i;
    
char ch;
    
float f;
    CString str;
    CString strResult;
    ar
>>i>>ch>>f>>str;
    strResult.Format(
"%d,%c,%f,%s",i,ch,f,str);
    MessageBox(strResult);
}



void  CGraphicDoc::Serialize(CArchive &  ar)
{
    
if (ar.IsStoring())
    
{
        
// TODO: add storing code here
        int i=5;
        
char ch='b';
        
float f =1.2f;
        CString str(
"http://www.zhangdali.org");
        ar
<<i<<ch<<f<<str;
    }

    
else
    
{
        
// TODO: add loading code here

        
int i;
        
char ch;
        
float f;
        CString str;
        CString strResult;
        ar
>>i>>ch>>f>>str;
        strResult.Format(
"%d,%c,%f,%s",i,ch,f,str);
        ::AfxMessageBox(strResult);

    }

}



CSettingDlg::CSettingDlg(CWnd
*  pParent  /*=NULL*/ )
    : CDialog(CSettingDlg::IDD, pParent)
{
    
//{{AFX_DATA_INIT(CSettingDlg)
    m_nLineWidth = 0;
    m_nLineStyle 
= -1;
    
//}}AFX_DATA_INIT
    m_clr = RGB(255,0,0);
    m_brush.CreateSolidBrush(RGB(
0,0,255));
    m_brush1.CreateSolidBrush(RGB(
0,255,0));
    m_font.CreatePointFont(
200,"华文行楷");
}


void  CSettingDlg::OnChangeLineWidth() 
{
    
// TODO: If this is a RICHEDIT control, the control will not
    
// send this notification unless you override the CDialog::OnInitDialog()
    
// function and call CRichEditCtrl().SetEventMask()
    
// with the ENM_CHANGE flag ORed into the mask.
    
    
// TODO: Add your control notification handler code here
    Invalidate();
}


 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值