void CMainWindow::OnPaint()
{
CPaintDC dc(this);
CBrush brush(RGB(0,0,0));
CRect rect;
GetClientRect(&rect);
dc.FillRect(&rect,&brush);
dc.SetROP2(R2_NOT);
dc.MoveTo(m_ptBegin);
dc.LineTo(m_ptEnd);
}
SetROP2在Programming Windows with MFC中是這樣解釋的
:When the GDI outputs pixels to a logical display surface, it doesn't simply output pixel colors. Rather, it combines the colors of the pixels that it's outputting with the colors of the pixels at the destination using a combination of Boolean operations.
讓人很不解,然後翻開Programming Windows看到是這樣的:
當Windows使用畫筆來畫線時,它實際上運行畫筆像素與目標位置處原來像素之間的某種位布爾運算。像素間的位布爾運算叫做“位映像運算”,簡稱爲“ROP”。由於畫一條直線只涉及兩種像素(畫筆和目標),因此這種布爾運算又稱爲“二元位映像運算”,簡記爲“ROP2”。Windows定義了16種ROP2代碼,表示Windows組合畫筆像素和目標像素的方式。
這就比較清楚了
然後自己在MFC中用R2_NOT實現了一下