I'm trying to adapt a screensaver written in C++ with WinAPIs to work for multiple monitors. I found this article that suggests to rewrite this basic WM_PAINT handler:
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'
}
Into something like this to incorporate drawing for multiple screens:
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;
}
But the question I have is what about special optimization/clipping that BeginPaint() sets up in the DC after processing WM_PAINT message? With this approach it will be lost. Any idea how to preserve it across the EnumDisplayMonitors() call?
The answer is actually described in the MSDN docs for EnumDisplayMonitors . When you pass an HDC parameter to EnumDisplayMonitors, then the DC it passes to your callback function is a subset of the DC that you originally passed in with these changes:
Note that in modern Windows (at least since Win8), you will never really see different color formats in practice for Window DCs since GDI always runs with 32-bit color.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.