我想下面的代码,但我得到我的第二个监视器上没有,但应该是我的绘画图像的黑色矩形(使用GDI)。有没有人听说过这个问题吗?我做第二个监视器上(位图或文字)任何绘图呈现为一个黑色的矩形。谢谢!
LRESULT WINAPI ScreenSaverProc(HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam)
{
static UINT uTimer; // timer identifier
// Handles screen saver messages
switch(message)
{
// <snip>
case WM_PAINT: // Sent when the system or another application makes a request to paint a portion of an application's window (e.g., UpdateWindow/RedrawWindow)
{
PAINTSTRUCT lpPaint = {0};
HDC hdc = BeginPaint(hwnd, &lpPaint );
EnumDisplayMonitors(hdc, NULL, MonitorNumProcPaint, 0); // For every monitor attached, call the passed in function
EndPaint(hwnd, &lpPaint);
return true;
}
// <snip>
}
}
BOOL CALLBACK MonitorNumProcPaint(HMONITOR hMonitor, HDC hdc, LPRECT lprcMonitor, LPARAM data)
{
// If the coordinates of the top left corner are 0,0, then we're rendering on the primary monitor, otherwise we're not.
if (lprcMonitor->left == 0 && lprcMonitor->top == 0)
return (PaintPrimaryDisplay(hMonitor, hdc, lprcMonitor, data));
else
return (PaintNonPrimaryDisplay(hMonitor, hdc, lprcMonitor, data));
}
bool PaintNonPrimaryDisplay(HMONITOR hMonitor, HDC hdc, LPRECT lprcMonitor, LPARAM data)
{
Gdiplus::Graphics * pGraphics = Gdiplus::Graphics::FromHDC(hdc);
if (gpBitmapMotivation2)
{
pGraphics->DrawImage(gpBitmapMotivation2, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top);
}
int sizeX = (int) ceil( (lprcMonitor->right - lprcMonitor->left) * SS_SCREEN_PERCENTAGE);
int sizeY = (int) ceil( (lprcMonitor->bottom- lprcMonitor->top) * SS_SCREEN_PERCENTAGE);
DrawMyText(lprcMonitor, sizeX, sizeY, pGraphics, "MyText"); // This custom function sets up the font, etc and renders the text.
BitBlt(hdc, lprcMonitor->left, lprcMonitor->top, lprcMonitor->right - lprcMonitor->left, lprcMonitor->bottom - lprcMonitor->top, hdc, lprcMonitor->left, lprcMonitor->top, SRCCOPY);
return true;
}