MFC繪圖 利用SetROP2(R2_NOTXORPEN)清除上一次繪製的圖案

函數概述

Windows API SetROP2(int nDrawMode)主要用於設定當前前景色的混合模式。R2_NOT就是取反的意思,即前景色爲背景色的反色,經常用R2_NOT來畫橡皮線,因爲兩次取反可以還原背景色

函數原型

int SetROP2( HDC hdc, int fnDrawMode);

清除上一次繪製的圖像

思路

  1. 設置繪製模式爲反背景色
  2. 畫上一個圖案
  3. 更新記錄上一個圖案的變量
  4. 畫當前的圖案
  5. 恢復繪製模式

代碼

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);//恢復之前的繪製模式
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章