我看书上的一个例子,是为了实现一个窗口中预先画了两个矩形,然后鼠标可以廓起来再画矩形,其中设置了,ROP2模式,不过我把这段代码去掉也没觉得有什么变化,请高手看看给点意见,小弟先谢过了
void CRopFunView::OnMouseMove(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
//CView::OnMouseMove(nFlags, point);
         CDC* pDC = GetDC();
SetDCProperties(pDC);
//将设备单元转换成逻辑单元
pDC->DPtoLP(&point); //表示鼠标位置是否在矩形区内
int bInside = FALSE; if((point.x > 0 && point.x <= XMAXCLIP_LOGICALUNITS) &&
(point.y > 0 && point.y <= YMAXCLIP_LOGICALUNITS))
{
//设置鼠标形状,同时将信号量设置为TRUE
::SetCursor(m_hcurCross);
bInside = TRUE;
}
else
{
//设置鼠标形状
::SetCursor(m_hcurArrow);
} //Draw coord text
CBrush brush;
//用来绘制文本区(红色)
if(bInside)
brush.CreateSolidBrush(RGB(0, 255, 0));
//用来绘制文本区(绿色)
else
brush.CreateSolidBrush(RGB(255, 0, 0));
CBrush *pOldbrush = pDC->SelectObject(&brush);
CString cs = "0000, 0000";
//获得文本区大小
CSize size = pDC->GetTextExtent(cs);
//注意格式:%04d中的0是用来在没有那位的时候用0来填充
cs.Format(" %04d, %04d", point.x, point.y);
//绘制坐标显示文本框的矩形区
pDC->Rectangle(10, - 50 -(size.cy * 2), 10 + size.cx,
               - 50 -(size.cy * 2) - size.cy);
pDC->SetBkMode(TRANSPARENT);
pDC->TextOut(10, -50 -(size.cy * 2), cs);
pDC->SelectObject(pOldbrush); //m_bIsTracking变量用于标明
if(m_bIsTracking)
{
//Save old clip region-------------从这里开始
CRect rect;
pDC->GetClipBox(rect);
CRgn oldClipRgn;
//创建一个矩形区域,并将它附加给一个CRgn对象
oldClipRgn.CreateRectRgn(rect.TopLeft().x,
                                           rect.TopLeft().y,
            rect.BottomRight().x                                  rect.BottomRight().y); //Create new clip region
CRect rectLogical(0, YMAXCLIP_LOGICALUNITS,
XMAXCLIP_LOGICALUNITS, 0);
pDC->LPtoDP(&rectLogical.TopLeft());
pDC->LPtoDP(&rectLogical.BottomRight());
CRect rectDevice(rectLogical.TopLeft(),                rectLogical.BottomRight());
CRgn region;
//创建一个由RECT结构定义的矩形区域,并将它附加给一个CRgn对象
region.CreateRectRgnIndirect(rectDevice);
pDC->SelectClipRgn(&region);--------------到这里结束 //Create red dash pen
CPen pen(PS_DOT, 2, COLORREF(RGB(255, 0, 0)));
CPen *oldpen = pDC->SelectObject(&pen); //Select ROP2 mode
//设置用画笔和画刷图上去之后
int ropOld = pDC->SetROP2(m_nROPMode); //Move to rectangle stretch initial point
        pDC->MoveTo(m_pointOrigin.x, m_pointOrigin.y);
//将画矩形动作放在OnMouseMove中是产生绘图结果的关键,也是多个矩形产生的原因
//Draw the previous rectangle
pDC->LineTo(m_pointOrigin.x, m_pointLast.y);
pDC->LineTo(m_pointLast.x, m_pointLast.y);
pDC->LineTo(m_pointLast.x, m_pointOrigin.y);
pDC->LineTo(m_pointOrigin.x, m_pointOrigin.y); //Draw the new rectangle
pDC->LineTo(m_pointOrigin.x, point.y);
pDC->LineTo(point.x, point.y);
    pDC->LineTo(point.x, m_pointOrigin.y);
pDC->LineTo(m_pointOrigin.x, m_pointOrigin.y); //Save this point for next OnPaint
m_pointLast.x = point.x;
m_pointLast.y = point.y;

pDC->SelectObject(oldpen);
pDC->SetROP2(ropOld); //Restore old clip region
//pDC->SelectClipRgn(&oldClipRgn);
}
}