我想在客户区的一个椭圆内画图(如直线,图片),椭圆外部将不显示,只显示椭圆内部的图,象photoshop在选区中画图那样,如何实现?

解决方案 »

  1.   

    怎么这么长时间没回复,你可以自己将贴子提前的。我的代码如下:
    //CRgnShowView是CView的派生类。
    BOOL CRgnShowView::PreCreateWindow(CREATESTRUCT& cs)
    {
    // TODO: Modify the Window class or styles here by modifying
    //  the CREATESTRUCT cs
    CBitmap bmp; bmp.LoadBitmap(IDB_BMP_LL);
    m_aBrush.CreatePatternBrush(&bmp); // CBrush m_aBrush;为类成员
    bmp.DeleteObject(); return CView::PreCreateWindow(cs);
    }void CRgnShowView::OnDraw(CDC* pDC)
    {
    CRgnShowDoc* pDoc = GetDocument();
    ASSERT_VALID(pDoc);
    // TODO: add draw code for native data here
    CRect aRect; GetClientRect(aRect);
    CRgn aRgn;
    aRgn.CreateEllipticRgnIndirect(aRect);
    pDC->FillRgn(&aRgn,&m_aBrush);
    }
      

  2.   

    比如,我要在一个矩形上画线,lineto可能画到矩形外面去,但只显示矩形内部的线
      

  3.   

    我想可以用ExtSelectClipRgn()来设定画图区域。
      

  4.   

    use SelectClipRgn too.CClientDC dc(this);
    CRect rcClient;
    CRgn rgn;
    GetClientRect(rcClient);
    rgn.CreateEllipticRgn(10,10,40,40);
    ::SelectClipRgn(dc.GetSafeHdc(), (HRGN)rgn.GetSafeHandle());
    dc.FillSolidRect(&rcClient, RGB(255,0,0));