[WTL]部分DC操作

1. SaveDC和RestoreDC.

说起来很费解,不如写个代码show下它们的能力~

// DCLib... ...
void Draw(HDC hdc)
{
// Draw a line (10, 10) - (190, 190)
MoveToEx(hdc, 10, 10, (LPPOINT)NULL);
LineTo(hdc, 190, 190);

// comments? [2]
SaveDC(hdc);

// comments? [1]
IntersectClipRect(hdc, 20, 20, 100, 100);

// Draw a rect [(10, 10) - (30, 30)]
RECT r = { 10, 10, 30, 30};
HBRUSH b = (HBRUSH)CreateSolidBrush(RGB(255, 0, 255));
FillRect(hdc, &r, b);

// comments? [2]
RestoreDC(hdc, -1);

MoveToEx(hdc, 20, 10, (LPPOINT)NULL);
LineTo(hdc, 190, 190);


int a = 0;
}



 

2. IntersectClipRect

可以用IntersectClipRect设定DC的可绘制范围(矩形),但是被Clip掉一部分的事实,怎么才能被Clear掉呢。

用SelectClipRgn(hdc, NULL);即可。

 

 

3. 

原文地址:https://www.cnblogs.com/healerkx/p/2236931.html