[英]WM_PAINT message and EnumDisplayMonitors
I'm trying to adapt a screensaver written in C++ with WinAPIs to work for multiple monitors. 我正在尝试使用WinAPIs用C ++编写的屏幕保护程序适用于多个监视器。 I found this article that suggests to rewrite this basic WM_PAINT handler: 我发现这篇文章建议重写此基本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'
}
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? 但是我有一个问题是,在处理WM_PAINT消息后,BeginPaint()在DC中设置的特殊优化/裁剪会如何? With this approach it will be lost. 用这种方法,它将丢失。 Any idea how to preserve it across the EnumDisplayMonitors() call? 知道如何在EnumDisplayMonitors()调用中保留它吗?
The answer is actually described in the MSDN docs for EnumDisplayMonitors . 答案实际上是在MSDN文档中的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: 当您将HDC参数传递给EnumDisplayMonitors时,传递给您的回调函数的DC是您最初通过以下更改传递的DC的子集:
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. 请注意,在现代Windows(至少从Win8开始)中,由于GDI始终以32位颜色运行,因此您将永远不会真正看到Window DC的不同颜色格式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.