函數概述
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);//恢復之前的繪製模式
}