繁体   English   中英

WM_PAINT消息和EnumDisplayMonitors

[英]WM_PAINT message and EnumDisplayMonitors

我正在尝试使用WinAPIs用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;
}

但是我有一个问题是,在处理WM_PAINT消息后,BeginPaint()在DC中设置的特殊优化/裁剪会如何? 用这种方法,它将丢失。 知道如何在EnumDisplayMonitors()调用中保留它吗?

答案实际上是在MSDN文档中的EnumDisplayMonitors中描述的。 当您将HDC参数传递给EnumDisplayMonitors时,传递给您的回调函数的DC是您最初通过以下更改传递的DC的子集:

  • 剪辑已进一步缩小,仅覆盖原始剪辑与监视器的剪辑矩形的交集。
  • DC的颜色格式适用于特定的监视器,而不适用于窗口的“主”监视器。

请注意,在现代Windows(至少从Win8开始)中,由于GDI始终以32位颜色运行,因此您将永远不会真正看到Window DC的不同颜色格式。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM