精华区 [关闭][返回]

当前位置:网易精华区>>讨论区精华>>编程开发>>C/C++>>图形图像及多媒体专题>>画图的问题?

主题:画图的问题?
发信人: lightsabre()
整理人: wenbobo(2002-07-10 16:43:27), 站内信件
如何使图形只能画在指定的区域内

For a SDI with normal CView:

void CClipTestView::OnDraw(CDC* pDC)
{
        CClipTestDoc* pDoc = GetDocument();
        ASSERT_VALID(pDoc);
        
         CRect rect, rcClip;

        GetClientRect(&rect);
        
        int nWidth = rect.Width();
        int nHeight = rect.Height();

        rcClip = CRect(rect.left+nWidth/4,rect.top+nHeight/4,rect.right-nWidt
h/4,rect.bottom-nHeight/4);

        CRgn rgn;

        rgn.CreateRectRgnIndirect(&rcClip);

        //comment out the following line to see the whole drawing
        pDC->SelectClipRgn(&rgn);

        pDC->MoveTo(rect.left,rect.top);
        pDC->LineTo(rect.right,rect.bottom);

        pDC->MoveTo(rect.right,rect.top);
        pDC->LineTo(rect.left,rect.bottom);

}

--
May The Force Be With You

※ 来源:.月光软件站 http://www.moon-soft.com.[FROM: 4.54.50.211]

[关闭][返回]