[英]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的子集:
請注意,在現代Windows(至少從Win8開始)中,由於GDI始終以32位顏色運行,因此您將永遠不會真正看到Window DC的不同顏色格式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.