函数概述
Windows API SetROP2(int nDrawMode)主要用于设定当前前景色的混合模式。R2_NOT就是取反的意思,即前景色为背景色的反色,经常用R2_NOT来画橡皮线,因为两次取反可以还原背景色
函数原型
int SetROP2( HDC hdc, int fnDrawMode);
清除上一次绘制的图像
思路
- 设置绘制模式为反背景色
- 画上一个图案
- 更新记录上一个图案的变量
- 画当前的图案
- 恢复绘制模式
代码
void OnLButtonUp(UINT nFlags, CPoint point)
CClientDC dc(this);//用户区画板
int oldmode = dc.SetROP2(R2_NOTXORPEN);//设置当前绘制模式为反背景色
CPoint m_last_point;
m_last_point.x = 5, m_last_point = 5;
dc.Ellipse(m_last_point-5, m_last_point-5, m_last_point+5, m_last_point+5);//在座标(5,5)处绘制一个半径为5的圆
m_last_point= point;//更新上一个座标为当前座标
dc.Ellipse(point-5, point-5, point+5, point+5);//在鼠标指针座标处画圆
dc.SetROP2(oldmode);//恢复之前的绘制模式
}