我正在尝试使用带有 WinAPI 的 C++ 编写的屏幕保护程序来适应多个监视器。我发现这篇文章建议重写这个基本的 WM_PAINT 处理程序:
case WM_PAINT:
{
PAINTSTRUCT ps = {0};
HDC hdc = BeginPaint(hWnd, &ps );
DoDrawing(hdc, ps.rcPaint);
EndPaint(hWnd, &ps);
}
break;
void DoDrawing(HDC hDC, RECT rcDraw)
{
//Do actual drawing in 'hDC'
}
像这样合并多个屏幕的绘图:
case WM_PAINT:
{
PAINTSTRUCT ps = {0};
HDC hdcE = BeginPaint(hWnd, &ps );
EnumDisplayMonitors(hdcE,NULL, MyPaintEnumProc, 0);
EndPaint(hWnd, &ps);
}
break;
BOOL CALLBACK MyPaintEnumProc(
HMONITOR hMonitor, // handle to display monitor
HDC hdc1, // handle to monitor DC
LPRECT lprcMonitor, // monitor intersection rectangle
LPARAM data // data
)
{
RECT rc = *lprcMonitor;
// you have the rect which has coordinates of the monitor
DoDrawing(hdc1, rc);
// Draw here now
return 1;
}
但是我的问题是 BeginPaint() 在处理 WM_PAINT 消息后在 DC 中设置的特殊优化/剪辑呢?使用这种方法,它将丢失。知道如何在 EnumDisplayMonitors() 调用中保留它吗?